23#include <com/sun/star/awt/Rectangle.hpp>
24#include <osl/diagnose.h>
28#include <oox/token/namespaces.hxx>
29#include <oox/token/tokens.hxx>
38sal_Int64 lclHmmToEmu( sal_Int32 nValue )
44sal_Int32 lclEmuToHmm( sal_Int64 nValue )
60 mbLocksWithSheet( true ),
61 mbPrintsWithSheet( true )
67 meAnchorType( ANCHOR_INVALID ),
69 meEditAs( ANCHOR_TWOCELL )
77 case XDR_TOKEN( absoluteAnchor ):
81 case XDR_TOKEN( oneCellAnchor ):
85 case XDR_TOKEN( twoCellAnchor ):
88 OUString sEditAs = rAttribs.
getXString( XML_editAs, OUString() );
89 if ( !sEditAs.isEmpty() )
91 if ( sEditAs.equalsIgnoreAsciiCase(
"absolute" ) )
93 else if ( sEditAs.equalsIgnoreAsciiCase(
"oneCell") )
95 else if (sEditAs.equalsIgnoreAsciiCase(
"twoCell") )
101 OSL_ENSURE(
false,
"ShapeAnchor::importAnchor - unexpected element" );
129 switch( nParentContext )
131 case XDR_TOKEN(
from ):
135 case XDR_TOKEN(
to ):
140 OSL_ENSURE(
false,
"ShapeAnchor::setCellPos - unexpected parent element" );
142 if( pCellAnchor )
switch( nElement )
148 default: OSL_ENSURE(
false,
"ShapeAnchor::setCellPos - unexpected element" );
157 sal_Int32 nValues[8];
177 OSL_FAIL(
"ShapeAnchor::importVmlAnchor - missing anchor tokens" );
193 EmuSize aPageSize( lclHmmToEmu( rPageSizeHmm.Width ), lclHmmToEmu( rPageSizeHmm.Height ) );
194 EmuRectangle aAnchorRect( -1, -1, -1, -1 );
200 OSL_ENSURE(
maPos.
isValid(),
"ShapeAnchor::calcAnchorRectEmu - invalid position" );
202 aAnchorRect.setPos(
maPos );
207 OSL_ENSURE(
maFrom.
isValid(),
"ShapeAnchor::calcAnchorRectEmu - invalid position" );
211 if( (aPoint.X < aPageSize.Width) && (aPoint.Y < aPageSize.Height) )
212 aAnchorRect.setPos( aPoint );
216 OSL_ENSURE(
false,
"ShapeAnchor::calcAnchorRectEmu - invalid anchor" );
221 if( (aAnchorRect.X >= 0) && (aAnchorRect.Y >= 0) )
switch(
meAnchorType )
225 OSL_ENSURE(
maSize.
isValid(),
"ShapeAnchor::calcAnchorRectEmu - invalid size" );
228 aAnchorRect.Width = ::std::min< sal_Int64 >(
maSize.
Width, aPageSize.Width - aAnchorRect.X );
229 aAnchorRect.Height = ::std::min< sal_Int64 >(
maSize.
Height, aPageSize.Height - aAnchorRect.Y );
234 OSL_ENSURE(
maTo.
isValid(),
"ShapeAnchor::calcAnchorRectEmu - invalid position" );
245 aAnchorRect.Width = aPageSize.Width - aAnchorRect.X;
247 aAnchorRect.Width = ::std::min< sal_Int64 >( aPoint.X - aAnchorRect.X + 1, aAnchorRect.Width );
249 aAnchorRect.Height = aPageSize.Height - aAnchorRect.Y;
251 aAnchorRect.Height = ::std::min< sal_Int64 >( aPoint.Y - aAnchorRect.Y + 1, aAnchorRect.Height );
264 return css::awt::Rectangle( lclEmuToHmm( aAnchorRect.X ), lclEmuToHmm( aAnchorRect.Y ), lclEmuToHmm( aAnchorRect.Width ), lclEmuToHmm( aAnchorRect.Height ) );
271 EmuPoint aEmuPoint( lclHmmToEmu( aPoint.X ), lclHmmToEmu( aPoint.Y ) );
std::optional< OUString > getXString(sal_Int32 nAttrToken) const
std::optional< sal_Int64 > getHyper(sal_Int32 nAttrToken) const
std::optional< bool > getBool(sal_Int32 nAttrToken) const
Converter for cell addresses and cell ranges for OOXML and BIFF filters.
bool checkRow(sal_Int32 nRow, bool bTrackOverflow)
Checks if the passed row index is valid.
bool checkCol(sal_Int32 nCol, bool bTrackOverflow)
Checks if the passed column index is valid.
ScAddress createValidCellAddress(const OUString &rString, sal_Int16 nSheet, bool bTrackOverflow)
Returns a valid cell address by moving it into allowed dimensions.
::oox::drawingml::EmuPoint calcCellAnchorEmu(const CellAnchorModel &rModel) const
Converts the passed anchor to an absolute position in EMUs.
AnchorSizeModel maSize
Top-left position, if anchor is of type absolute.
AnchorPointModel maPos
Type of the cell anchor models.
::oox::drawingml::EmuRectangle calcAnchorRectEmu(const css::awt::Size &rPageSizeHmm) const
Calculates the resulting shape anchor in EMUs.
void importExt(const AttributeList &rAttribs)
Imports the absolute anchor size from the xdr:ext element.
@ ANCHOR_ONECELL
Absolute anchor (top-left corner and size in absolute units).
@ ANCHOR_TWOCELL
One-cell anchor (top-left corner at cell, size in absolute units).
@ ANCHOR_VML
Two-cell anchor (top-left and bottom-right corner at cell).
@ ANCHOR_ABSOLUTE
Anchor type is unknown.
CellAnchorType meCellAnchorType
Type of this shape anchor.
CellAnchorModel maTo
Top-left position, if anchor is not of type absolute.
void importVmlAnchor(std::u16string_view rAnchor)
Imports the client anchor settings from a VML element.
void importAnchor(sal_Int32 nElement, const AttributeList &rAttribs)
Imports the shape anchor (one of the elements xdr:absoluteAnchor, xdr:oneCellAnchor,...
CellAnchorType
Specifies how cell positions from CellAnchorModel have to be processed.
@ Pixel
Offsets are given in EMUs.
void setCellPos(sal_Int32 nElement, sal_Int32 nParentContext, std::u16string_view rValue)
Sets an attribute of the cell-dependent anchor position from xdr:from and xdr:to elements.
css::awt::Rectangle calcAnchorRectHmm(const css::awt::Size &rPageSizeHmm) const
Calculates the resulting shape anchor in 1/100 mm.
AnchorClientDataModel maClientData
Bottom-right position, if anchor is of type two-cell.
bool isAnchorValid() const
Checks whether the shape is visible based on the anchor.
CellAnchorModel maFrom
Anchor size, if anchor is not of type two-cell.
void importPos(const AttributeList &rAttribs)
Imports the absolute anchor position from the xdr:pos element.
AnchorType meEditAs
Shape client data.
void importClientData(const AttributeList &rAttribs)
Imports the shape client data from the xdr:clientData element.
ShapeAnchor(const WorksheetHelper &rHelper)
Helper class that provides functions to convert values from and to different units.
double scaleValue(double fValue, Unit eFromUnit, Unit eToUnit) const
Converts the passed value between the passed units.
AddressConverter & getAddressConverter() const
Returns the converter for string to cell address/range conversion.
UnitConverter & getUnitConverter() const
Returns the measurement unit converter.
css::awt::Point getCellPosition(sal_Int32 nCol, sal_Int32 nRow) const
Returns the absolute cell position in 1/100 mm.
SCTAB getSheetIndex() const
Returns the index of the current sheet.
RttiCompleteObjectLocator col
sal_Int32 toInt32(std::u16string_view str, sal_Int16 radix=10)
sal_Int64 toInt64(std::u16string_view str, sal_Int16 radix=10)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
sal_Int32 convertEmuToHmm(sal_Int64 nValue)
sal_Int64 convertHmmToEmu(sal_Int32 nValue)
@ ScreenX
English Metric Unit (1/360,000 cm).
@ ScreenY
Horizontal screen pixels.
A 2D cell address struct for binary filters.
Position in spreadsheet (cell position and offset inside cell).
sal_Int64 mnRowOffset
X offset inside the column.
sal_Int64 mnColOffset
Row index.
CellAnchorModel()
Y offset inside the row.
sal_Int32 mnRow
Column index.