1*e3508121SAndrew Rist /**************************************************************
2*e3508121SAndrew Rist  *
3*e3508121SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*e3508121SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*e3508121SAndrew Rist  * distributed with this work for additional information
6*e3508121SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*e3508121SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*e3508121SAndrew Rist  * "License"); you may not use this file except in compliance
9*e3508121SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*e3508121SAndrew Rist  *
11*e3508121SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*e3508121SAndrew Rist  *
13*e3508121SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*e3508121SAndrew Rist  * software distributed under the License is distributed on an
15*e3508121SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*e3508121SAndrew Rist  * KIND, either express or implied.  See the License for the
17*e3508121SAndrew Rist  * specific language governing permissions and limitations
18*e3508121SAndrew Rist  * under the License.
19*e3508121SAndrew Rist  *
20*e3508121SAndrew Rist  *************************************************************/
21*e3508121SAndrew Rist 
22*e3508121SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef OOX_DRAWINGML_CHART_CHARTDRAWINGFRAGMENT_HXX
25cdf0e10cSrcweir #define OOX_DRAWINGML_CHART_CHARTDRAWINGFRAGMENT_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "oox/core/fragmenthandler2.hxx"
28cdf0e10cSrcweir #include "oox/drawingml/shape.hxx"
29cdf0e10cSrcweir 
30cdf0e10cSrcweir namespace oox {
31cdf0e10cSrcweir namespace drawingml {
32cdf0e10cSrcweir namespace chart {
33cdf0e10cSrcweir 
34cdf0e10cSrcweir // ============================================================================
35cdf0e10cSrcweir 
36cdf0e10cSrcweir /** Relative shape position in a chart object. */
37cdf0e10cSrcweir struct AnchorPosModel
38cdf0e10cSrcweir {
39cdf0e10cSrcweir     double              mfX;                /// X coordinate relative to chart object (0.0 to 1.0).
40cdf0e10cSrcweir     double              mfY;                /// Y coordinate relative to chart object (0.0 to 1.0).
41cdf0e10cSrcweir 
AnchorPosModeloox::drawingml::chart::AnchorPosModel42cdf0e10cSrcweir     inline explicit     AnchorPosModel() : mfX( -1.0 ), mfY( -1.0 ) {}
isValidoox::drawingml::chart::AnchorPosModel43cdf0e10cSrcweir     inline bool         isValid() const { return (0.0 <= mfX) && (mfX <= 1.0) && (0.0 <= mfY) && (mfY <= 1.0); }
44cdf0e10cSrcweir };
45cdf0e10cSrcweir 
46cdf0e10cSrcweir // ----------------------------------------------------------------------------
47cdf0e10cSrcweir 
48cdf0e10cSrcweir /** Absolute shape size in a chart object (in EMUs). */
49cdf0e10cSrcweir struct AnchorSizeModel : public EmuSize
50cdf0e10cSrcweir {
AnchorSizeModeloox::drawingml::chart::AnchorSizeModel51cdf0e10cSrcweir     inline explicit     AnchorSizeModel() : EmuSize( -1, -1 ) {}
isValidoox::drawingml::chart::AnchorSizeModel52cdf0e10cSrcweir     inline bool         isValid() const { return (Width >= 0) && (Height >= 0); }
53cdf0e10cSrcweir };
54cdf0e10cSrcweir 
55cdf0e10cSrcweir // ============================================================================
56cdf0e10cSrcweir 
57cdf0e10cSrcweir /** Contains the position of a shape in the chart object. Supports different
58cdf0e10cSrcweir     shape anchor modes (absolute, relative).
59cdf0e10cSrcweir  */
60cdf0e10cSrcweir class ShapeAnchor
61cdf0e10cSrcweir {
62cdf0e10cSrcweir public:
63cdf0e10cSrcweir     explicit            ShapeAnchor( bool bRelSize );
64cdf0e10cSrcweir 
65cdf0e10cSrcweir     /** Imports the absolute anchor size from the cdr:ext element. */
66cdf0e10cSrcweir     void                importExt( const AttributeList& rAttribs );
67cdf0e10cSrcweir     /** Sets an the relative anchor position from the cdr:from or cdr:to element. */
68cdf0e10cSrcweir     void                setPos( sal_Int32 nElement, sal_Int32 nParentContext, const ::rtl::OUString& rValue );
69cdf0e10cSrcweir 
70cdf0e10cSrcweir     /** Calculates the resulting shape anchor in EMUs. */
71cdf0e10cSrcweir     EmuRectangle        calcAnchorRectEmu( const EmuRectangle& rChartRect ) const;
72cdf0e10cSrcweir 
73cdf0e10cSrcweir private:
74cdf0e10cSrcweir     AnchorPosModel      maFrom;             /// Top-left position relative to chart object.
75cdf0e10cSrcweir     AnchorPosModel      maTo;               /// Bottom-right position relative to chart object.
76cdf0e10cSrcweir     AnchorSizeModel     maSize;             /// Shape size, if anchor has absolute size.
77cdf0e10cSrcweir     bool                mbRelSize;          /// True = relative size, false = absolute size.
78cdf0e10cSrcweir };
79cdf0e10cSrcweir 
80cdf0e10cSrcweir typedef ::boost::shared_ptr< ShapeAnchor > ShapeAnchorRef;
81cdf0e10cSrcweir 
82cdf0e10cSrcweir // ============================================================================
83cdf0e10cSrcweir 
84cdf0e10cSrcweir /** Handler for a chart drawing fragment (c:userShapes root element).
85cdf0e10cSrcweir  */
86cdf0e10cSrcweir class ChartDrawingFragment : public ::oox::core::FragmentHandler2
87cdf0e10cSrcweir {
88cdf0e10cSrcweir public:
89cdf0e10cSrcweir     explicit            ChartDrawingFragment(
90cdf0e10cSrcweir                             ::oox::core::XmlFilterBase& rFilter,
91cdf0e10cSrcweir                             const ::rtl::OUString& rFragmentPath,
92cdf0e10cSrcweir                             const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxDrawPage,
93cdf0e10cSrcweir                             const ::com::sun::star::awt::Size& rChartSize,
94cdf0e10cSrcweir                             const ::com::sun::star::awt::Point& rShapesOffset,
95cdf0e10cSrcweir                             bool bOleSupport );
96cdf0e10cSrcweir     virtual             ~ChartDrawingFragment();
97cdf0e10cSrcweir 
98cdf0e10cSrcweir     virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs );
99cdf0e10cSrcweir     virtual void        onCharacters( const ::rtl::OUString& rChars );
100cdf0e10cSrcweir     virtual void        onEndElement();
101cdf0e10cSrcweir 
102cdf0e10cSrcweir private:
103cdf0e10cSrcweir     ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >
104cdf0e10cSrcweir                         mxDrawPage;             /// Drawing page of this sheet.
105cdf0e10cSrcweir     ::oox::drawingml::ShapePtr mxShape;         /// Current top-level shape.
106cdf0e10cSrcweir     ShapeAnchorRef      mxAnchor;               /// Current anchor of top-level shape.
107cdf0e10cSrcweir     EmuRectangle        maChartRectEmu;         /// Position and size of the chart object for embedded shapes (in EMUs).
108cdf0e10cSrcweir     bool                mbOleSupport;           /// True = allow to insert OLE objects into the drawing page.
109cdf0e10cSrcweir };
110cdf0e10cSrcweir 
111cdf0e10cSrcweir // ============================================================================
112cdf0e10cSrcweir 
113cdf0e10cSrcweir } // namespace chart
114cdf0e10cSrcweir } // namespace drawingml
115cdf0e10cSrcweir } // namespace oox
116cdf0e10cSrcweir 
117cdf0e10cSrcweir #endif
118