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_SHAPE_HXX 25 #define OOX_DRAWINGML_SHAPE_HXX 26 27 #include "oox/helper/propertymap.hxx" 28 #include "oox/drawingml/drawingmltypes.hxx" 29 #include "oox/drawingml/customshapeproperties.hxx" 30 #include "oox/drawingml/textliststyle.hxx" 31 32 #include <com/sun/star/frame/XModel.hpp> 33 #include <com/sun/star/drawing/XDrawPage.hpp> 34 #include <boost/shared_ptr.hpp> 35 #include <boost/enable_shared_from_this.hpp> 36 #include <vector> 37 #include <map> 38 39 namespace oox { namespace vml { 40 struct OleObjectInfo; 41 } } 42 43 namespace oox { namespace drawingml { 44 45 class CustomShapeProperties; 46 typedef boost::shared_ptr< CustomShapeProperties > CustomShapePropertiesPtr; 47 48 typedef ::std::map< ::rtl::OUString, ShapePtr > ShapeIdMap; 49 50 struct ShapeStyleRef 51 { 52 Color maPhClr; 53 sal_Int32 mnThemedIdx; 54 }; 55 56 typedef ::std::map< sal_Int32, ShapeStyleRef > ShapeStyleRefMap; 57 58 // ============================================================================ 59 60 /** Additional information for a chart embedded in a drawing shape. */ 61 struct ChartShapeInfo 62 { 63 ::rtl::OUString maFragmentPath; /// Path to related XML stream, e.g. for charts. 64 bool mbEmbedShapes; /// True = load chart shapes into chart, false = load into parent drawpage. 65 ChartShapeInfooox::drawingml::ChartShapeInfo66 inline explicit ChartShapeInfo( bool bEmbedShapes ) : mbEmbedShapes( bEmbedShapes ) {} 67 }; 68 69 // ============================================================================ 70 71 class Shape 72 : public boost::enable_shared_from_this< Shape > 73 { 74 public: 75 76 explicit Shape( const sal_Char* pServiceType = 0 ); 77 virtual ~Shape(); 78 getServiceName()79 rtl::OUString& getServiceName(){ return msServiceName; } 80 void setServiceName( const sal_Char* pServiceName ); 81 getShapeProperties()82 PropertyMap& getShapeProperties(){ return maShapeProperties; } 83 getLineProperties()84 inline LineProperties& getLineProperties() { return *mpLinePropertiesPtr; } getLineProperties() const85 inline const LineProperties& getLineProperties() const { return *mpLinePropertiesPtr; } 86 getFillProperties()87 inline FillProperties& getFillProperties() { return *mpFillPropertiesPtr; } getFillProperties() const88 inline const FillProperties& getFillProperties() const { return *mpFillPropertiesPtr; } 89 getGraphicProperties()90 inline GraphicProperties& getGraphicProperties() { return *mpGraphicPropertiesPtr; } getGraphicProperties() const91 inline const GraphicProperties& getGraphicProperties() const { return *mpGraphicPropertiesPtr; } 92 getCustomShapeProperties()93 CustomShapePropertiesPtr getCustomShapeProperties(){ return mpCustomShapePropertiesPtr; } 94 95 table::TablePropertiesPtr getTableProperties(); 96 setPosition(com::sun::star::awt::Point nPosition)97 void setPosition( com::sun::star::awt::Point nPosition ){ maPosition = nPosition; } setSize(com::sun::star::awt::Size aSize)98 void setSize( com::sun::star::awt::Size aSize ){ maSize = aSize; } setRotation(sal_Int32 nRotation)99 void setRotation( sal_Int32 nRotation ) { mnRotation = nRotation; } setFlip(sal_Bool bFlipH,sal_Bool bFlipV)100 void setFlip( sal_Bool bFlipH, sal_Bool bFlipV ) { mbFlipH = bFlipH; mbFlipV = bFlipV; } addChild(const ShapePtr pChildPtr)101 void addChild( const ShapePtr pChildPtr ) { maChildren.push_back( pChildPtr ); } getChildren()102 std::vector< ShapePtr >& getChildren() { return maChildren; } 103 setName(const rtl::OUString & rName)104 void setName( const rtl::OUString& rName ) { msName = rName; } getName()105 ::rtl::OUString getName( ) { return msName; } setId(const rtl::OUString & rId)106 void setId( const rtl::OUString& rId ) { msId = rId; } setHidden(sal_Bool bHidden)107 void setHidden( sal_Bool bHidden ) { mbHidden = bHidden; } getHidden() const108 sal_Bool getHidden() const { return mbHidden; }; setSubType(sal_Int32 nSubType)109 void setSubType( sal_Int32 nSubType ) { mnSubType = nSubType; } getSubType() const110 sal_Int32 getSubType() const { return mnSubType; } setSubTypeIndex(sal_uInt32 nSubTypeIndex)111 void setSubTypeIndex( sal_uInt32 nSubTypeIndex ) { mnSubTypeIndex = nSubTypeIndex; } getSubTypeIndex() const112 sal_Int32 getSubTypeIndex() const { return mnSubTypeIndex; } 113 114 // setDefaults has to be called if styles are imported (OfficeXML is not storing properties having the default value) 115 void setDefaults(); 116 117 ::oox::vml::OleObjectInfo& setOleObjectType(); 118 ChartShapeInfo& setChartType( bool bEmbedShapes ); 119 void setDiagramType(); 120 void setTableType(); 121 122 void setTextBody(const TextBodyPtr & pTextBody); 123 TextBodyPtr getTextBody(); 124 void setMasterTextListStyle( const TextListStylePtr& pMasterTextListStyle ); getMasterTextListStyle() const125 TextListStylePtr getMasterTextListStyle() const { return mpMasterTextListStyle; } 126 getShapeStyleRefs()127 inline ShapeStyleRefMap& getShapeStyleRefs() { return maShapeStyleRefs; } getShapeStyleRefs() const128 inline const ShapeStyleRefMap& getShapeStyleRefs() const { return maShapeStyleRefs; } 129 const ShapeStyleRef* getShapeStyleRef( sal_Int32 nRefType ) const; 130 131 // addShape is creating and inserting the corresponding XShape. 132 void addShape( 133 ::oox::core::XmlFilterBase& rFilterBase, 134 const Theme* pTheme, 135 const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes, 136 const ::com::sun::star::awt::Rectangle* pShapeRect = 0, 137 ShapeIdMap* pShapeMap = 0 ); 138 setXShape(const::com::sun::star::uno::Reference<::com::sun::star::drawing::XShape> & rXShape)139 void setXShape( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& rXShape ) 140 { mxShape = rXShape; }; 141 const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > & getXShape() const142 getXShape() const { return mxShape; } 143 144 virtual void applyShapeReference( const Shape& rReferencedShape ); 145 146 protected: 147 148 ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > 149 createAndInsert( 150 ::oox::core::XmlFilterBase& rFilterBase, 151 const ::rtl::OUString& rServiceName, 152 const Theme* pTheme, 153 const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes, 154 const ::com::sun::star::awt::Rectangle* pShapeRect, 155 sal_Bool bClearText ); 156 157 void addChildren( 158 ::oox::core::XmlFilterBase& rFilterBase, 159 Shape& rMaster, 160 const Theme* pTheme, 161 const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes, 162 const ::com::sun::star::awt::Rectangle& rClientRect, 163 ShapeIdMap* pShapeMap ); 164 165 virtual ::rtl::OUString finalizeServiceName( 166 ::oox::core::XmlFilterBase& rFilter, 167 const ::rtl::OUString& rServiceName, 168 const ::com::sun::star::awt::Rectangle& rShapeRect ); 169 170 virtual void finalizeXShape( 171 ::oox::core::XmlFilterBase& rFilter, 172 const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes ); 173 174 std::vector< ShapePtr > maChildren; // only used for group shapes 175 TextBodyPtr mpTextBody; 176 LinePropertiesPtr mpLinePropertiesPtr; 177 FillPropertiesPtr mpFillPropertiesPtr; 178 GraphicPropertiesPtr mpGraphicPropertiesPtr; 179 CustomShapePropertiesPtr mpCustomShapePropertiesPtr; 180 table::TablePropertiesPtr mpTablePropertiesPtr; 181 PropertyMap maShapeProperties; 182 TextListStylePtr mpMasterTextListStyle; 183 ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > mxShape; 184 185 rtl::OUString msServiceName; 186 rtl::OUString msName; 187 rtl::OUString msId; 188 sal_Int32 mnSubType; // if this type is not zero, then the shape is a placeholder 189 sal_Int32 mnSubTypeIndex; 190 191 ShapeStyleRefMap maShapeStyleRefs; 192 193 com::sun::star::awt::Size maSize; 194 com::sun::star::awt::Point maPosition; 195 196 private: 197 enum FrameType 198 { 199 FRAMETYPE_GENERIC, /// Generic shape, no special type. 200 FRAMETYPE_OLEOBJECT, /// OLE object embedded in a shape. 201 FRAMETYPE_CHART, /// Chart embedded in a shape. 202 FRAMETYPE_DIAGRAM, /// Complex diagram drawing shape. 203 FRAMETYPE_TABLE /// A table embedded in a shape. 204 }; 205 206 typedef ::boost::shared_ptr< ::oox::vml::OleObjectInfo > OleObjectInfoRef; 207 typedef ::boost::shared_ptr< ChartShapeInfo > ChartShapeInfoRef; 208 209 FrameType meFrameType; /// Type for graphic frame shapes. 210 OleObjectInfoRef mxOleObjectInfo; /// Additional data for OLE objects. 211 ChartShapeInfoRef mxChartShapeInfo; /// Additional data for chart shapes. 212 213 sal_Int32 mnRotation; 214 sal_Bool mbFlipH; 215 sal_Bool mbFlipV; 216 sal_Bool mbHidden; 217 }; 218 219 ::rtl::OUString GetShapeType( sal_Int32 nType ); 220 221 // ============================================================================ 222 223 } } 224 225 #endif // OOX_DRAWINGML_SHAPE_HXX 226