Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef OOX_XLS_DRAWINGBASE_HXX
30 : : #define OOX_XLS_DRAWINGBASE_HXX
31 : :
32 : : #include "oox/drawingml/drawingmltypes.hxx"
33 : : #include "worksheethelper.hxx"
34 : :
35 : : #include <com/sun/star/drawing/XShape.hpp>
36 : : #include <com/sun/star/table/XCell.hpp>
37 : :
38 : : namespace oox {
39 : : namespace xls {
40 : :
41 : : // ============================================================================
42 : :
43 : : /** Absolute position in a spreadsheet (in EMUs) independent from cells. */
44 : : struct AnchorPointModel : public ::oox::drawingml::EmuPoint
45 : : {
46 : 6 : inline explicit AnchorPointModel() : ::oox::drawingml::EmuPoint( -1, -1 ) {}
47 [ # # ][ # # ]: 0 : inline bool isValid() const { return (X >= 0) && (Y >= 0); }
48 : : };
49 : :
50 : : // ----------------------------------------------------------------------------
51 : :
52 : : /** Absolute size in a spreadsheet (in EMUs). */
53 : : struct AnchorSizeModel : public ::oox::drawingml::EmuSize
54 : : {
55 : 6 : inline explicit AnchorSizeModel() : ::oox::drawingml::EmuSize( -1, -1 ) {}
56 [ # # ][ # # ]: 0 : inline bool isValid() const { return (Width >= 0) && (Height >= 0); }
57 : : };
58 : :
59 : : // ----------------------------------------------------------------------------
60 : :
61 : : /** Position in spreadsheet (cell position and offset inside cell). */
62 : : struct CellAnchorModel
63 : : {
64 : : sal_Int32 mnCol; /// Column index.
65 : : sal_Int32 mnRow; /// Row index.
66 : : sal_Int64 mnColOffset; /// X offset inside the column.
67 : : sal_Int64 mnRowOffset; /// Y offset inside the row.
68 : :
69 : : explicit CellAnchorModel();
70 [ + - ][ + - ]: 12 : inline bool isValid() const { return (mnCol >= 0) && (mnRow >= 0); }
71 : : };
72 : :
73 : : // ----------------------------------------------------------------------------
74 : :
75 : : /** Application-specific client data of a shape. */
76 : : struct AnchorClientDataModel
77 : : {
78 : : bool mbLocksWithSheet;
79 : : bool mbPrintsWithSheet;
80 : :
81 : : explicit AnchorClientDataModel();
82 : : };
83 : :
84 : : // ============================================================================
85 : :
86 : : /** Contains the position of a shape in the spreadsheet. Supports different
87 : : shape anchor modes (absolute, one-cell, two-cell). */
88 [ - + ]: 6 : class ShapeAnchor : public WorksheetHelper
89 : : {
90 : : public:
91 : : explicit ShapeAnchor( const WorksheetHelper& rHelper );
92 : :
93 : : /** Imports the shape anchor (one of the elements xdr:absoluteAnchor, xdr:oneCellAnchor, xdr:twoCellAnchor). */
94 : : void importAnchor( sal_Int32 nElement, const AttributeList& rAttribs );
95 : : /** Imports the absolute anchor position from the xdr:pos element. */
96 : : void importPos( const AttributeList& rAttribs );
97 : : /** Imports the absolute anchor size from the xdr:ext element. */
98 : : void importExt( const AttributeList& rAttribs );
99 : : /** Imports the shape client data from the xdr:clientData element. */
100 : : void importClientData( const AttributeList& rAttribs );
101 : : /** Sets an attribute of the cell-dependent anchor position from xdr:from and xdr:to elements. */
102 : : void setCellPos( sal_Int32 nElement, sal_Int32 nParentContext, const ::rtl::OUString& rValue );
103 : : /** Imports the client anchor settings from a VML element. */
104 : : void importVmlAnchor( const ::rtl::OUString& rAnchor );
105 : :
106 : : /** Calculates the resulting shape anchor in EMUs. */
107 : : ::oox::drawingml::EmuRectangle calcAnchorRectEmu(
108 : : const ::com::sun::star::awt::Size& rPageSizeHmm ) const;
109 : : /** Calculates the resulting shape anchor in 1/100 mm. */
110 : : ::com::sun::star::awt::Rectangle calcAnchorRectHmm(
111 : : const ::com::sun::star::awt::Size& rPageSizeHmm ) const;
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 : : enum AnchorType
118 : : {
119 : : ANCHOR_INVALID, /// Anchor type is unknown.
120 : : ANCHOR_ABSOLUTE, /// Absolute anchor (top-left corner and size in absolute units).
121 : : ANCHOR_ONECELL, /// One-cell anchor (top-left corner at cell, size in absolute units).
122 : : ANCHOR_TWOCELL, /// Two-cell anchor (top-left and bottom-right corner at cell).
123 : : ANCHOR_VML
124 : : };
125 : :
126 : : /** Specifies how cell positions from CellAnchorModel have to be processed. */
127 : : enum CellAnchorType
128 : : {
129 : : CELLANCHOR_EMU, /// Offsets are given in EMUs.
130 : : CELLANCHOR_PIXEL, /// Offsets are given in screen pixels.
131 : : CELLANCHOR_COLROW /// Offsets are given in fractions of column width or row height.
132 : : };
133 : :
134 : : AnchorType meAnchorType; /// Type of this shape anchor.
135 : : CellAnchorType meCellAnchorType; /// Type of the cell anchor models.
136 : : AnchorPointModel maPos; /// Top-left position, if anchor is of type absolute.
137 : : AnchorSizeModel maSize; /// Anchor size, if anchor is not of type two-cell.
138 : : CellAnchorModel maFrom; /// Top-left position, if anchor is not of type absolute.
139 : : CellAnchorModel maTo; /// Bottom-right position, if anchor is of type two-cell.
140 : : AnchorClientDataModel maClientData; /// Shape client data.
141 : : sal_Int32 mnEditAs; /// Anchor mode as shown in the UI.
142 : : };
143 : :
144 : : // ============================================================================
145 : :
146 : : } // namespace xls
147 : : } // namespace oox
148 : :
149 : : #endif
150 : :
151 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|