xref: /aoo4110/main/oox/inc/oox/xls/drawingbase.hxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef OOX_XLS_DRAWINGBASE_HXX
25 #define OOX_XLS_DRAWINGBASE_HXX
26 
27 #include "oox/drawingml/drawingmltypes.hxx"
28 #include "oox/xls/worksheethelper.hxx"
29 
30 namespace oox {
31 namespace xls {
32 
33 // ============================================================================
34 
35 /** Absolute position in a spreadsheet (in EMUs) independent from cells. */
36 struct AnchorPointModel : public ::oox::drawingml::EmuPoint
37 {
AnchorPointModeloox::xls::AnchorPointModel38     inline explicit     AnchorPointModel() : ::oox::drawingml::EmuPoint( -1, -1 ) {}
isValidoox::xls::AnchorPointModel39     inline bool         isValid() const { return (X >= 0) && (Y >= 0); }
40 };
41 
42 // ----------------------------------------------------------------------------
43 
44 /** Absolute size in a spreadsheet (in EMUs). */
45 struct AnchorSizeModel : public ::oox::drawingml::EmuSize
46 {
AnchorSizeModeloox::xls::AnchorSizeModel47     inline explicit     AnchorSizeModel() : ::oox::drawingml::EmuSize( -1, -1 ) {}
isValidoox::xls::AnchorSizeModel48     inline bool         isValid() const { return (Width >= 0) && (Height >= 0); }
49 };
50 
51 // ----------------------------------------------------------------------------
52 
53 /** Position in spreadsheet (cell position and offset inside cell). */
54 struct CellAnchorModel
55 {
56     sal_Int32           mnCol;              /// Column index.
57     sal_Int32           mnRow;              /// Row index.
58     sal_Int64           mnColOffset;        /// X offset inside the column.
59     sal_Int64           mnRowOffset;        /// Y offset inside the row.
60 
61     explicit            CellAnchorModel();
isValidoox::xls::CellAnchorModel62     inline bool         isValid() const { return (mnCol >= 0) && (mnRow >= 0); }
63 };
64 
65 // ----------------------------------------------------------------------------
66 
67 /** Application-specific client data of a shape. */
68 struct AnchorClientDataModel
69 {
70     bool                mbLocksWithSheet;
71     bool                mbPrintsWithSheet;
72 
73     explicit            AnchorClientDataModel();
74 };
75 
76 // ============================================================================
77 
78 /** Contains the position of a shape in the spreadsheet. Supports different
79     shape anchor modes (absolute, one-cell, two-cell). */
80 class ShapeAnchor : public WorksheetHelper
81 {
82 public:
83     explicit            ShapeAnchor( const WorksheetHelper& rHelper );
84 
85     /** Imports the shape anchor (one of the elements xdr:absoluteAnchor, xdr:oneCellAnchor, xdr:twoCellAnchor). */
86     void                importAnchor( sal_Int32 nElement, const AttributeList& rAttribs );
87     /** Imports the absolute anchor position from the xdr:pos element. */
88     void                importPos( const AttributeList& rAttribs );
89     /** Imports the absolute anchor size from the xdr:ext element. */
90     void                importExt( const AttributeList& rAttribs );
91     /** Imports the shape client data from the xdr:clientData element. */
92     void                importClientData( const AttributeList& rAttribs );
93     /** Sets an attribute of the cell-dependent anchor position from xdr:from and xdr:to elements. */
94     void                setCellPos( sal_Int32 nElement, sal_Int32 nParentContext, const ::rtl::OUString& rValue );
95     /** Imports the client anchor settings from a VML element. */
96     void                importVmlAnchor( const ::rtl::OUString& rAnchor );
97     /** Imports the client anchor settings from a BIFF or DFF stream. */
98     void                importBiffAnchor( BinaryInputStream& rStrm );
99 
100     /** Calculates the resulting shape anchor in EMUs. */
101     ::oox::drawingml::EmuRectangle calcAnchorRectEmu(
102                             const ::com::sun::star::awt::Size& rPageSizeHmm ) const;
103     /** Calculates the resulting shape anchor in 1/100 mm. */
104     ::com::sun::star::awt::Rectangle calcAnchorRectHmm(
105                             const ::com::sun::star::awt::Size& rPageSizeHmm ) const;
106 
107 private:
108     /** Converts the passed anchor to an absolute position in EMUs. */
109     ::oox::drawingml::EmuPoint calcCellAnchorEmu( const CellAnchorModel& rModel ) const;
110 
111 private:
112     enum AnchorType
113     {
114         ANCHOR_INVALID,         /// Anchor type is unknown.
115         ANCHOR_ABSOLUTE,        /// Absolute anchor (top-left corner and size in absolute units).
116         ANCHOR_ONECELL,         /// One-cell anchor (top-left corner at cell, size in absolute units).
117         ANCHOR_TWOCELL          /// Two-cell anchor (top-left and bottom-right corner at cell).
118     };
119 
120     /** Specifies how cell positions from CellAnchorModel have to be processed. */
121     enum CellAnchorType
122     {
123         CELLANCHOR_EMU,             /// Offsets are given in EMUs.
124         CELLANCHOR_PIXEL,           /// Offsets are given in screen pixels.
125         CELLANCHOR_COLROW           /// Offsets are given in fractions of column width or row height.
126     };
127 
128     AnchorType          meAnchorType;       /// Type of this shape anchor.
129     CellAnchorType      meCellAnchorType;   /// Type of the cell anchor models.
130     AnchorPointModel    maPos;              /// Top-left position, if anchor is of type absolute.
131     AnchorSizeModel     maSize;             /// Anchor size, if anchor is not of type two-cell.
132     CellAnchorModel     maFrom;             /// Top-left position, if anchor is not of type absolute.
133     CellAnchorModel     maTo;               /// Bottom-right position, if anchor is of type two-cell.
134     AnchorClientDataModel maClientData;     /// Shape client data.
135     sal_Int32           mnEditAs;           /// Anchor mode as shown in the UI.
136 };
137 
138 // ============================================================================
139 
140 } // namespace xls
141 } // namespace oox
142 
143 #endif
144