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 INCLUDED_SC_SOURCE_FILTER_INC_DRAWINGBASE_HXX
21 : #define INCLUDED_SC_SOURCE_FILTER_INC_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 : /** Absolute position in a spreadsheet (in EMUs) independent from cells. */
33 : struct AnchorPointModel : public ::oox::drawingml::EmuPoint
34 : {
35 100 : inline explicit AnchorPointModel() : ::oox::drawingml::EmuPoint( -1, -1 ) {}
36 0 : inline bool isValid() const { return (X >= 0) && (Y >= 0); }
37 : };
38 :
39 : /** Absolute size in a spreadsheet (in EMUs). */
40 : struct AnchorSizeModel : public ::oox::drawingml::EmuSize
41 : {
42 100 : inline explicit AnchorSizeModel() : ::oox::drawingml::EmuSize( -1, -1 ) {}
43 0 : inline bool isValid() const { return (Width >= 0) && (Height >= 0); }
44 : };
45 :
46 : /** Position in spreadsheet (cell position and offset inside cell). */
47 : struct CellAnchorModel
48 : {
49 : sal_Int32 mnCol; /// Column index.
50 : sal_Int32 mnRow; /// Row index.
51 : sal_Int64 mnColOffset; /// X offset inside the column.
52 : sal_Int64 mnRowOffset; /// Y offset inside the row.
53 :
54 : explicit CellAnchorModel();
55 200 : inline bool isValid() const { return (mnCol >= 0) && (mnRow >= 0); }
56 : };
57 :
58 : /** Application-specific client data of a shape. */
59 : struct AnchorClientDataModel
60 : {
61 : bool mbLocksWithSheet;
62 : bool mbPrintsWithSheet;
63 :
64 : explicit AnchorClientDataModel();
65 : };
66 :
67 : /** Contains the position of a shape in the spreadsheet. Supports different
68 : shape anchor modes (absolute, one-cell, two-cell). */
69 197 : class ShapeAnchor : public WorksheetHelper
70 : {
71 : public:
72 : enum AnchorType
73 : {
74 : ANCHOR_INVALID, /// Anchor type is unknown.
75 : ANCHOR_ABSOLUTE, /// Absolute anchor (top-left corner and size in absolute units).
76 : ANCHOR_ONECELL, /// One-cell anchor (top-left corner at cell, size in absolute units).
77 : ANCHOR_TWOCELL, /// Two-cell anchor (top-left and bottom-right corner at cell).
78 : ANCHOR_VML
79 : };
80 : explicit ShapeAnchor( const WorksheetHelper& rHelper );
81 :
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, const OUString& rValue );
92 : /** Imports the client anchor settings from a VML element. */
93 : void importVmlAnchor( const OUString& rAnchor );
94 :
95 : /** Calculates the resulting shape anchor in EMUs. */
96 : ::oox::drawingml::EmuRectangle calcAnchorRectEmu(
97 : const ::com::sun::star::awt::Size& rPageSizeHmm ) const;
98 : /** Calculates the resulting shape anchor in 1/100 mm. */
99 : ::com::sun::star::awt::Rectangle calcAnchorRectHmm(
100 : const ::com::sun::star::awt::Size& rPageSizeHmm ) const;
101 97 : AnchorType getEditAs() const { return meEditAs; }
102 : private:
103 : /** Converts the passed anchor to an absolute position in EMUs. */
104 : ::oox::drawingml::EmuPoint calcCellAnchorEmu( const CellAnchorModel& rModel ) const;
105 :
106 : private:
107 :
108 : /** Specifies how cell positions from CellAnchorModel have to be processed. */
109 : enum CellAnchorType
110 : {
111 : CELLANCHOR_EMU, /// Offsets are given in EMUs.
112 : CELLANCHOR_PIXEL, /// Offsets are given in screen pixels.
113 : CELLANCHOR_COLROW /// Offsets are given in fractions of column width or row height.
114 : };
115 :
116 : AnchorType meAnchorType; /// Type of this shape anchor.
117 : CellAnchorType meCellAnchorType; /// Type of the cell anchor models.
118 : AnchorPointModel maPos; /// Top-left position, if anchor is of type absolute.
119 : AnchorSizeModel maSize; /// Anchor size, if anchor is not of type two-cell.
120 : CellAnchorModel maFrom; /// Top-left position, if anchor is not of type absolute.
121 : CellAnchorModel maTo; /// Bottom-right position, if anchor is of type two-cell.
122 : AnchorClientDataModel maClientData; /// Shape client data.
123 : AnchorType meEditAs; /// Anchor mode as shown in the UI.
124 : };
125 :
126 : } // namespace xls
127 : } // namespace oox
128 :
129 : #endif
130 :
131 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|