Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef OOX_XLS_DRAWINGBASE_HXX
21 : #define OOX_XLS_DRAWINGBASE_HXX
22 :
23 : #include "oox/drawingml/drawingmltypes.hxx"
24 : #include "worksheethelper.hxx"
25 :
26 : #include <com/sun/star/drawing/XShape.hpp>
27 : #include <com/sun/star/table/XCell.hpp>
28 :
29 : namespace oox {
30 : namespace xls {
31 :
32 : // ============================================================================
33 :
34 : /** Absolute position in a spreadsheet (in EMUs) independent from cells. */
35 : struct AnchorPointModel : public ::oox::drawingml::EmuPoint
36 : {
37 4 : inline explicit AnchorPointModel() : ::oox::drawingml::EmuPoint( -1, -1 ) {}
38 0 : inline bool isValid() const { return (X >= 0) && (Y >= 0); }
39 : };
40 :
41 : // ----------------------------------------------------------------------------
42 :
43 : /** Absolute size in a spreadsheet (in EMUs). */
44 : struct AnchorSizeModel : public ::oox::drawingml::EmuSize
45 : {
46 4 : inline explicit AnchorSizeModel() : ::oox::drawingml::EmuSize( -1, -1 ) {}
47 0 : inline bool isValid() const { return (Width >= 0) && (Height >= 0); }
48 : };
49 :
50 : // ----------------------------------------------------------------------------
51 :
52 : /** Position in spreadsheet (cell position and offset inside cell). */
53 : struct CellAnchorModel
54 : {
55 : sal_Int32 mnCol; /// Column index.
56 : sal_Int32 mnRow; /// Row index.
57 : sal_Int64 mnColOffset; /// X offset inside the column.
58 : sal_Int64 mnRowOffset; /// Y offset inside the row.
59 :
60 : explicit CellAnchorModel();
61 8 : inline bool isValid() const { return (mnCol >= 0) && (mnRow >= 0); }
62 : };
63 :
64 : // ----------------------------------------------------------------------------
65 :
66 : /** Application-specific client data of a shape. */
67 : struct AnchorClientDataModel
68 : {
69 : bool mbLocksWithSheet;
70 : bool mbPrintsWithSheet;
71 :
72 : explicit AnchorClientDataModel();
73 : };
74 :
75 : // ============================================================================
76 :
77 : /** Contains the position of a shape in the spreadsheet. Supports different
78 : shape anchor modes (absolute, one-cell, two-cell). */
79 6 : class ShapeAnchor : public WorksheetHelper
80 : {
81 : public:
82 : enum AnchorType
83 : {
84 : ANCHOR_INVALID, /// Anchor type is unknown.
85 : ANCHOR_ABSOLUTE, /// Absolute anchor (top-left corner and size in absolute units).
86 : ANCHOR_ONECELL, /// One-cell anchor (top-left corner at cell, size in absolute units).
87 : ANCHOR_TWOCELL, /// Two-cell anchor (top-left and bottom-right corner at cell).
88 : ANCHOR_VML
89 : };
90 : explicit ShapeAnchor( const WorksheetHelper& rHelper );
91 :
92 : /** Imports the shape anchor (one of the elements xdr:absoluteAnchor, xdr:oneCellAnchor, xdr:twoCellAnchor). */
93 : void importAnchor( sal_Int32 nElement, const AttributeList& rAttribs );
94 : /** Imports the absolute anchor position from the xdr:pos element. */
95 : void importPos( const AttributeList& rAttribs );
96 : /** Imports the absolute anchor size from the xdr:ext element. */
97 : void importExt( const AttributeList& rAttribs );
98 : /** Imports the shape client data from the xdr:clientData element. */
99 : void importClientData( const AttributeList& rAttribs );
100 : /** Sets an attribute of the cell-dependent anchor position from xdr:from and xdr:to elements. */
101 : void setCellPos( sal_Int32 nElement, sal_Int32 nParentContext, const OUString& rValue );
102 : /** Imports the client anchor settings from a VML element. */
103 : void importVmlAnchor( const OUString& rAnchor );
104 :
105 : /** Calculates the resulting shape anchor in EMUs. */
106 : ::oox::drawingml::EmuRectangle calcAnchorRectEmu(
107 : const ::com::sun::star::awt::Size& rPageSizeHmm ) const;
108 : /** Calculates the resulting shape anchor in 1/100 mm. */
109 : ::com::sun::star::awt::Rectangle calcAnchorRectHmm(
110 : const ::com::sun::star::awt::Size& rPageSizeHmm ) const;
111 2 : AnchorType getEditAs() const { return meEditAs; }
112 : private:
113 : /** Converts the passed anchor to an absolute position in EMUs. */
114 : ::oox::drawingml::EmuPoint calcCellAnchorEmu( const CellAnchorModel& rModel ) const;
115 :
116 : private:
117 :
118 :
119 : /** Specifies how cell positions from CellAnchorModel have to be processed. */
120 : enum CellAnchorType
121 : {
122 : CELLANCHOR_EMU, /// Offsets are given in EMUs.
123 : CELLANCHOR_PIXEL, /// Offsets are given in screen pixels.
124 : CELLANCHOR_COLROW /// Offsets are given in fractions of column width or row height.
125 : };
126 :
127 : AnchorType meAnchorType; /// Type of this shape anchor.
128 : CellAnchorType meCellAnchorType; /// Type of the cell anchor models.
129 : AnchorPointModel maPos; /// Top-left position, if anchor is of type absolute.
130 : AnchorSizeModel maSize; /// Anchor size, if anchor is not of type two-cell.
131 : CellAnchorModel maFrom; /// Top-left position, if anchor is not of type absolute.
132 : CellAnchorModel maTo; /// Bottom-right position, if anchor is of type two-cell.
133 : AnchorClientDataModel maClientData; /// Shape client data.
134 : AnchorType meEditAs; /// Anchor mode as shown in the UI.
135 : };
136 :
137 : // ============================================================================
138 :
139 : } // namespace xls
140 : } // namespace oox
141 :
142 : #endif
143 :
144 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|