1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include <oox/drawingml/drawingmltypes.hxx>
23 #include "worksheethelper.hxx"
25 namespace oox
{ class AttributeList
; }
29 /** Absolute position in a spreadsheet (in EMUs) independent from cells. */
30 struct AnchorPointModel
: public ::oox::drawingml::EmuPoint
32 explicit AnchorPointModel() : ::oox::drawingml::EmuPoint( -1, -1 ) {}
33 bool isValid() const { return (X
>= 0) && (Y
>= 0); }
36 /** Absolute size in a spreadsheet (in EMUs). */
37 struct AnchorSizeModel
: public ::oox::drawingml::EmuSize
39 explicit AnchorSizeModel() : ::oox::drawingml::EmuSize( -1, -1 ) {}
40 bool isValid() const { return (Width
>= 0) && (Height
>= 0); }
43 /** Position in spreadsheet (cell position and offset inside cell). */
44 struct CellAnchorModel
46 sal_Int32 mnCol
; /// Column index.
47 sal_Int32 mnRow
; /// Row index.
48 sal_Int64 mnColOffset
; /// X offset inside the column.
49 sal_Int64 mnRowOffset
; /// Y offset inside the row.
51 explicit CellAnchorModel();
52 bool isValid() const { return (mnCol
>= 0) && (mnRow
>= 0); }
55 /** Application-specific client data of a shape. */
56 struct AnchorClientDataModel
58 bool mbLocksWithSheet
;
59 bool mbPrintsWithSheet
;
61 explicit AnchorClientDataModel();
64 /** Contains the position of a shape in the spreadsheet. Supports different
65 shape anchor modes (absolute, one-cell, two-cell). */
66 class ShapeAnchor final
: public WorksheetHelper
71 ANCHOR_INVALID
, /// Anchor type is unknown.
72 ANCHOR_ABSOLUTE
, /// Absolute anchor (top-left corner and size in absolute units).
73 /// Matches our "Page" anchor -> ScAnchorType::SCA_PAGE
74 ANCHOR_ONECELL
, /// One-cell anchor (top-left corner at cell, size in absolute units).
75 /// Matches our "Cell" anchor -> ScAnchorType::SCA_CELL
76 ANCHOR_TWOCELL
, /// Two-cell anchor (top-left and bottom-right corner at cell).
77 /// Matches our "Cell (resize with cell)" anchor -> ScAnchorType::SCA_CELL_RESIZE
80 explicit ShapeAnchor( const WorksheetHelper
& rHelper
);
82 /** Imports the shape anchor (one of the elements xdr:absoluteAnchor, xdr:oneCellAnchor, xdr:twoCellAnchor). */
83 void importAnchor( sal_Int32 nElement
, const AttributeList
& rAttribs
);
84 /** Imports the absolute anchor position from the xdr:pos element. */
85 void importPos( const AttributeList
& rAttribs
);
86 /** Imports the absolute anchor size from the xdr:ext element. */
87 void importExt( const AttributeList
& rAttribs
);
88 /** Imports the shape client data from the xdr:clientData element. */
89 void importClientData( const AttributeList
& rAttribs
);
90 /** Sets an attribute of the cell-dependent anchor position from xdr:from and xdr:to elements. */
91 void setCellPos( sal_Int32 nElement
, sal_Int32 nParentContext
, std::u16string_view rValue
);
92 /** Imports the client anchor settings from a VML element. */
93 void importVmlAnchor( std::u16string_view rAnchor
);
95 /** Checks whether the shape is visible based on the anchor
97 If From and To anchor has the same attribute values, the shape
98 will not have width and height and thus we can assume that
99 such kind of shape will be not be visible
101 bool isAnchorValid() const;
103 /** Calculates the resulting shape anchor in EMUs. */
104 ::oox::drawingml::EmuRectangle
calcAnchorRectEmu( const css::awt::Size
& rPageSizeHmm
) const;
105 /** Calculates the resulting shape anchor in 1/100 mm. */
106 css::awt::Rectangle
calcAnchorRectHmm( const css::awt::Size
& rPageSizeHmm
) const;
107 AnchorType
getEditAs() const { return meEditAs
; }
109 /** Converts the passed anchor to an absolute position in EMUs. */
110 ::oox::drawingml::EmuPoint
calcCellAnchorEmu( const CellAnchorModel
& rModel
) const;
114 /** Specifies how cell positions from CellAnchorModel have to be processed. */
115 enum class CellAnchorType
117 Emu
, /// Offsets are given in EMUs.
118 Pixel
, /// Offsets are given in screen pixels.
121 AnchorType meAnchorType
; /// Type of this shape anchor.
122 CellAnchorType meCellAnchorType
; /// Type of the cell anchor models.
123 AnchorPointModel maPos
; /// Top-left position, if anchor is of type absolute.
124 AnchorSizeModel maSize
; /// Anchor size, if anchor is not of type two-cell.
125 CellAnchorModel maFrom
; /// Top-left position, if anchor is not of type absolute.
126 CellAnchorModel maTo
; /// Bottom-right position, if anchor is of type two-cell.
127 AnchorClientDataModel maClientData
; /// Shape client data.
128 AnchorType meEditAs
; /// Anchor mode as shown in the UI.
131 } // namespace oox::xls
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */