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_DRAWINGML_CHART_CHARTDRAWINGFRAGMENT_HXX 25 #define OOX_DRAWINGML_CHART_CHARTDRAWINGFRAGMENT_HXX 26 27 #include "oox/core/fragmenthandler2.hxx" 28 #include "oox/drawingml/shape.hxx" 29 30 namespace oox { 31 namespace drawingml { 32 namespace chart { 33 34 // ============================================================================ 35 36 /** Relative shape position in a chart object. */ 37 struct AnchorPosModel 38 { 39 double mfX; /// X coordinate relative to chart object (0.0 to 1.0). 40 double mfY; /// Y coordinate relative to chart object (0.0 to 1.0). 41 AnchorPosModeloox::drawingml::chart::AnchorPosModel42 inline explicit AnchorPosModel() : mfX( -1.0 ), mfY( -1.0 ) {} isValidoox::drawingml::chart::AnchorPosModel43 inline bool isValid() const { return (0.0 <= mfX) && (mfX <= 1.0) && (0.0 <= mfY) && (mfY <= 1.0); } 44 }; 45 46 // ---------------------------------------------------------------------------- 47 48 /** Absolute shape size in a chart object (in EMUs). */ 49 struct AnchorSizeModel : public EmuSize 50 { AnchorSizeModeloox::drawingml::chart::AnchorSizeModel51 inline explicit AnchorSizeModel() : EmuSize( -1, -1 ) {} isValidoox::drawingml::chart::AnchorSizeModel52 inline bool isValid() const { return (Width >= 0) && (Height >= 0); } 53 }; 54 55 // ============================================================================ 56 57 /** Contains the position of a shape in the chart object. Supports different 58 shape anchor modes (absolute, relative). 59 */ 60 class ShapeAnchor 61 { 62 public: 63 explicit ShapeAnchor( bool bRelSize ); 64 65 /** Imports the absolute anchor size from the cdr:ext element. */ 66 void importExt( const AttributeList& rAttribs ); 67 /** Sets an the relative anchor position from the cdr:from or cdr:to element. */ 68 void setPos( sal_Int32 nElement, sal_Int32 nParentContext, const ::rtl::OUString& rValue ); 69 70 /** Calculates the resulting shape anchor in EMUs. */ 71 EmuRectangle calcAnchorRectEmu( const EmuRectangle& rChartRect ) const; 72 73 private: 74 AnchorPosModel maFrom; /// Top-left position relative to chart object. 75 AnchorPosModel maTo; /// Bottom-right position relative to chart object. 76 AnchorSizeModel maSize; /// Shape size, if anchor has absolute size. 77 bool mbRelSize; /// True = relative size, false = absolute size. 78 }; 79 80 typedef ::boost::shared_ptr< ShapeAnchor > ShapeAnchorRef; 81 82 // ============================================================================ 83 84 /** Handler for a chart drawing fragment (c:userShapes root element). 85 */ 86 class ChartDrawingFragment : public ::oox::core::FragmentHandler2 87 { 88 public: 89 explicit ChartDrawingFragment( 90 ::oox::core::XmlFilterBase& rFilter, 91 const ::rtl::OUString& rFragmentPath, 92 const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxDrawPage, 93 const ::com::sun::star::awt::Size& rChartSize, 94 const ::com::sun::star::awt::Point& rShapesOffset, 95 bool bOleSupport ); 96 virtual ~ChartDrawingFragment(); 97 98 virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ); 99 virtual void onCharacters( const ::rtl::OUString& rChars ); 100 virtual void onEndElement(); 101 102 private: 103 ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes > 104 mxDrawPage; /// Drawing page of this sheet. 105 ::oox::drawingml::ShapePtr mxShape; /// Current top-level shape. 106 ShapeAnchorRef mxAnchor; /// Current anchor of top-level shape. 107 EmuRectangle maChartRectEmu; /// Position and size of the chart object for embedded shapes (in EMUs). 108 bool mbOleSupport; /// True = allow to insert OLE objects into the drawing page. 109 }; 110 111 // ============================================================================ 112 113 } // namespace chart 114 } // namespace drawingml 115 } // namespace oox 116 117 #endif 118