Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sc / source / filter / inc / drawingbase.hxx
blob244779eeb5ceeb0d85e73ce6dff841f6543b938e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #ifndef INCLUDED_SC_SOURCE_FILTER_INC_DRAWINGBASE_HXX
21 #define INCLUDED_SC_SOURCE_FILTER_INC_DRAWINGBASE_HXX
23 #include <oox/drawingml/drawingmltypes.hxx>
24 #include "worksheethelper.hxx"
26 namespace oox { class AttributeList; }
28 namespace oox {
29 namespace xls {
31 /** Absolute position in a spreadsheet (in EMUs) independent from cells. */
32 struct AnchorPointModel : public ::oox::drawingml::EmuPoint
34 explicit AnchorPointModel() : ::oox::drawingml::EmuPoint( -1, -1 ) {}
35 bool isValid() const { return (X >= 0) && (Y >= 0); }
38 /** Absolute size in a spreadsheet (in EMUs). */
39 struct AnchorSizeModel : public ::oox::drawingml::EmuSize
41 explicit AnchorSizeModel() : ::oox::drawingml::EmuSize( -1, -1 ) {}
42 bool isValid() const { return (Width >= 0) && (Height >= 0); }
45 /** Position in spreadsheet (cell position and offset inside cell). */
46 struct CellAnchorModel
48 sal_Int32 mnCol; /// Column index.
49 sal_Int32 mnRow; /// Row index.
50 sal_Int64 mnColOffset; /// X offset inside the column.
51 sal_Int64 mnRowOffset; /// Y offset inside the row.
53 explicit CellAnchorModel();
54 bool isValid() const { return (mnCol >= 0) && (mnRow >= 0); }
57 /** Application-specific client data of a shape. */
58 struct AnchorClientDataModel
60 bool mbLocksWithSheet;
61 bool mbPrintsWithSheet;
63 explicit AnchorClientDataModel();
66 /** Contains the position of a shape in the spreadsheet. Supports different
67 shape anchor modes (absolute, one-cell, two-cell). */
68 class ShapeAnchor : public WorksheetHelper
70 public:
71 enum AnchorType
73 ANCHOR_INVALID, /// Anchor type is unknown.
74 ANCHOR_ABSOLUTE, /// Absolute anchor (top-left corner and size in absolute units).
75 /// Matches our "Page" anchor -> ScAnchorType::SCA_PAGE
76 ANCHOR_ONECELL, /// One-cell anchor (top-left corner at cell, size in absolute units).
77 /// Matches our "Cell" anchor -> ScAnchorType::SCA_CELL
78 ANCHOR_TWOCELL, /// Two-cell anchor (top-left and bottom-right corner at cell).
79 /// Matches our "Cell (resize with cell)" anchor -> ScAnchorType::SCA_CELL_RESIZE
80 ANCHOR_VML
82 explicit ShapeAnchor( const WorksheetHelper& rHelper );
84 /** Imports the shape anchor (one of the elements xdr:absoluteAnchor, xdr:oneCellAnchor, xdr:twoCellAnchor). */
85 void importAnchor( sal_Int32 nElement, const AttributeList& rAttribs );
86 /** Imports the absolute anchor position from the xdr:pos element. */
87 void importPos( const AttributeList& rAttribs );
88 /** Imports the absolute anchor size from the xdr:ext element. */
89 void importExt( const AttributeList& rAttribs );
90 /** Imports the shape client data from the xdr:clientData element. */
91 void importClientData( const AttributeList& rAttribs );
92 /** Sets an attribute of the cell-dependent anchor position from xdr:from and xdr:to elements. */
93 void setCellPos( sal_Int32 nElement, sal_Int32 nParentContext, const OUString& rValue );
94 /** Imports the client anchor settings from a VML element. */
95 void importVmlAnchor( const OUString& rAnchor );
97 /** Checks whether the shape is visible based on the anchor
99 If From and To anchor has the same attribute values, the shape
100 will not have width and height and thus we can assume that
101 such kind of shape will be not be visible
103 bool isAnchorValid() const;
105 /** Calculates the resulting shape anchor in EMUs. */
106 ::oox::drawingml::EmuRectangle calcAnchorRectEmu( const css::awt::Size& rPageSizeHmm ) const;
107 /** Calculates the resulting shape anchor in 1/100 mm. */
108 css::awt::Rectangle calcAnchorRectHmm( const css::awt::Size& rPageSizeHmm ) const;
109 AnchorType getEditAs() const { return meEditAs; }
110 private:
111 /** Converts the passed anchor to an absolute position in EMUs. */
112 ::oox::drawingml::EmuPoint calcCellAnchorEmu( const CellAnchorModel& rModel ) const;
114 private:
116 /** Specifies how cell positions from CellAnchorModel have to be processed. */
117 enum class CellAnchorType
119 Emu, /// Offsets are given in EMUs.
120 Pixel, /// Offsets are given in screen pixels.
123 AnchorType meAnchorType; /// Type of this shape anchor.
124 CellAnchorType meCellAnchorType; /// Type of the cell anchor models.
125 AnchorPointModel maPos; /// Top-left position, if anchor is of type absolute.
126 AnchorSizeModel maSize; /// Anchor size, if anchor is not of type two-cell.
127 CellAnchorModel maFrom; /// Top-left position, if anchor is not of type absolute.
128 CellAnchorModel maTo; /// Bottom-right position, if anchor is of type two-cell.
129 AnchorClientDataModel maClientData; /// Shape client data.
130 AnchorType meEditAs; /// Anchor mode as shown in the UI.
133 } // namespace xls
134 } // namespace oox
136 #endif
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */