Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / include / oox / drawingml / shape.hxx
blobccf477bef805dcc22d26b736635c390846cd8a29
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_OOX_DRAWINGML_SHAPE_HXX
21 #define INCLUDED_OOX_DRAWINGML_SHAPE_HXX
23 #include <map>
24 #include <memory>
25 #include <string_view>
26 #include <vector>
28 #include <com/sun/star/awt/Point.hpp>
29 #include <com/sun/star/awt/Size.hpp>
30 #include <com/sun/star/beans/PropertyValue.hpp>
31 #include <com/sun/star/uno/Reference.hxx>
32 #include <com/sun/star/uno/Sequence.hxx>
34 #include <oox/core/xmlfilterbase.hxx>
35 #include <oox/dllapi.h>
36 #include <oox/drawingml/color.hxx>
37 #include <oox/drawingml/connectorshapecontext.hxx>
38 #include <oox/drawingml/drawingmltypes.hxx>
39 #include <oox/helper/helper.hxx>
40 #include <oox/helper/propertymap.hxx>
41 #include <rtl/ustring.hxx>
42 #include <sal/types.h>
44 namespace basegfx { class B2DHomMatrix; }
46 namespace com::sun::star {
47 namespace awt { struct Rectangle; }
48 namespace drawing { class XShape; }
49 namespace drawing { class XShapes; }
50 namespace uno { class Any; }
53 namespace oox::core {
54 class XmlFilterBase;
57 namespace oox::vml {
58 struct OleObjectInfo;
61 namespace svx::diagram {
62 class IDiagramHelper;
65 namespace oox::drawingml {
67 class Theme;
68 struct EffectProperties;
69 struct FillProperties;
70 struct GraphicProperties;
71 struct LineProperties;
72 struct Shape3DProperties;
74 class CustomShapeProperties;
75 typedef std::shared_ptr< CustomShapeProperties > CustomShapePropertiesPtr;
77 typedef ::std::map< OUString, ShapePtr > ShapeIdMap;
79 typedef std::vector<ConnectorShapeProperties> ConnectorShapePropertiesList;
81 struct ShapeStyleRef
83 Color maPhClr;
84 sal_Int32 mnThemedIdx;
85 ShapeStyleRef() : mnThemedIdx(0) {}
88 typedef ::std::map< sal_Int32, ShapeStyleRef > ShapeStyleRefMap;
90 /** Additional information for a chart embedded in a drawing shape. */
91 struct ChartShapeInfo
93 OUString maFragmentPath; ///< Path to related XML stream, e.g. for charts.
94 bool mbEmbedShapes; ///< True = load chart shapes into chart, false = load into parent drawpage.
96 explicit ChartShapeInfo( bool bEmbedShapes ) : mbEmbedShapes( bEmbedShapes ) {}
99 /// Attributes for a linked textbox.
100 struct LinkedTxbxAttr
102 sal_Int32 id;
103 sal_Int32 seq;
104 LinkedTxbxAttr(): id(0),seq(0){};
107 class Diagram;
109 class OOX_DLLPUBLIC Shape
110 : public std::enable_shared_from_this< Shape >
112 public:
114 explicit Shape( const char* pServiceType = nullptr, bool bDefaultHeight = true );
115 explicit Shape( const ShapePtr& pSourceShape );
116 Shape(Shape const &) = default;
117 virtual ~Shape();
118 Shape & operator =(Shape const &) = default;
120 OUString& getServiceName(){ return msServiceName; }
121 void setServiceName( const char* pServiceName );
123 const OUString& getDiagramDataModelID() const { return msDiagramDataModelID; }
124 void setDiagramDataModelID( const OUString& rDiagramDataModelID ) { msDiagramDataModelID = rDiagramDataModelID; }
126 PropertyMap& getShapeProperties(){ return maShapeProperties; }
128 LineProperties& getLineProperties() { return *mpLinePropertiesPtr; }
129 const LineProperties& getLineProperties() const { return *mpLinePropertiesPtr; }
131 FillProperties& getFillProperties() { return *mpFillPropertiesPtr; }
132 const FillProperties& getFillProperties() const { return *mpFillPropertiesPtr; }
134 GraphicProperties& getGraphicProperties() { return *mpGraphicPropertiesPtr; }
135 const GraphicProperties& getGraphicProperties() const { return *mpGraphicPropertiesPtr; }
137 CustomShapePropertiesPtr& getCustomShapeProperties(){ return mpCustomShapePropertiesPtr; }
139 OUString& getConnectorName() { return msConnectorName; }
140 std::vector<OUString>& getConnectorAdjustments() { return maConnectorAdjustmentList; };
141 ConnectorShapePropertiesList& getConnectorShapeProperties() { return maConnectorShapePropertiesList; }
142 void setConnectorShape(bool bConnector) { mbConnector = bConnector; }
143 bool isConnectorShape() const { return mbConnector; }
145 Shape3DProperties& get3DProperties() { return *mp3DPropertiesPtr; }
146 const Shape3DProperties& get3DProperties() const { return *mp3DPropertiesPtr; }
148 table::TablePropertiesPtr const & getTableProperties();
150 EffectProperties& getEffectProperties() const { return *mpEffectPropertiesPtr; }
152 void setChildPosition( css::awt::Point nPosition ){ maChPosition = nPosition; }
153 void setChildSize( css::awt::Size aSize ){ maChSize = aSize; }
155 void setPosition( css::awt::Point nPosition ){ maPosition = nPosition; }
156 const css::awt::Point& getPosition() const { return maPosition; }
158 void setSize( css::awt::Size aSize ){ maSize = aSize; }
159 const css::awt::Size& getSize() const { return maSize; }
161 void setRotation( sal_Int32 nRotation ) { mnRotation = nRotation; }
162 sal_Int32 getRotation() const { return mnRotation; }
163 void setDiagramRotation( sal_Int32 nRotation ) { mnDiagramRotation = nRotation; }
164 void setFlip( bool bFlipH, bool bFlipV ) { mbFlipH = bFlipH; mbFlipV = bFlipV; }
165 bool getFlipH() const { return mbFlipH; }
166 bool getFlipV() const { return mbFlipV; }
167 void addChild( const ShapePtr& rChildPtr ) { maChildren.push_back( rChildPtr ); }
168 std::vector< ShapePtr >& getChildren() { return maChildren; }
170 void setName( const OUString& rName ) { msName = rName; }
171 const OUString& getName( ) const { return msName; }
172 void setInternalName( const OUString& rInternalName ) { msInternalName = rInternalName; }
173 const OUString& getInternalName() const { return msInternalName; }
174 void setId( const OUString& rId ) { msId = rId; }
175 const OUString& getId() const { return msId; }
176 void setDescription( const OUString& rDescr ) { msDescription = rDescr; }
177 void setDecorative(bool const isDecorative) { m_isDecorative = isDecorative; }
178 void setHidden( bool bHidden ) { mbHidden = bHidden; }
179 void setHiddenMasterShape( bool bHiddenMasterShape ) { mbHiddenMasterShape = bHiddenMasterShape; }
180 void setLocked( bool bLocked ) { mbLocked = bLocked; }
181 void setSubType( sal_Int32 nSubType ) { mnSubType = nSubType; }
182 sal_Int32 getSubType() const { return mnSubType; }
183 void setSubTypeIndex( sal_Int32 nSubTypeIndex ) { moSubTypeIndex = nSubTypeIndex; }
184 const std::optional< sal_Int32 >& getSubTypeIndex() const { return moSubTypeIndex; }
186 // setDefaults has to be called if styles are imported (OfficeXML is not storing properties having the default value)
187 void setDefaults(bool bHeight);
189 ::oox::vml::OleObjectInfo& setOleObjectType();
190 ChartShapeInfo& setChartType( bool bEmbedShapes );
191 void setDiagramType();
192 void setTableType();
194 void setTextBody(const TextBodyPtr & pTextBody);
195 const TextBodyPtr& getTextBody() const { return mpTextBody;}
196 void setMasterTextListStyle( const TextListStylePtr& pMasterTextListStyle );
197 const TextListStylePtr& getMasterTextListStyle() const { return mpMasterTextListStyle; }
199 ShapeStyleRefMap& getShapeStyleRefs() { return maShapeStyleRefs; }
200 const ShapeStyleRefMap& getShapeStyleRefs() const { return maShapeStyleRefs; }
201 const ShapeStyleRef* getShapeStyleRef( sal_Int32 nRefType ) const;
202 bool hasShapeStyleRefs() const { return !maShapeStyleRefs.empty(); }
204 // addShape is creating and inserting the corresponding XShape.
205 void addShape(
206 ::oox::core::XmlFilterBase& rFilterBase,
207 const Theme* pTheme,
208 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
209 const basegfx::B2DHomMatrix& aTransformation,
210 const FillProperties& rShapeOrParentShapeFillProps,
211 ShapeIdMap* pShapeMap = nullptr,
212 oox::drawingml::ShapePtr pParentGroupShape = nullptr);
214 const css::uno::Reference< css::drawing::XShape > &
215 getXShape() const { return mxShape; }
217 void applyShapeReference( const Shape& rReferencedShape, bool bUseText = true );
218 const ::std::vector<OUString>&
219 getExtDrawings() const { return maExtDrawings; }
220 void addExtDrawingRelId( const OUString &rRelId ) { maExtDrawings.push_back( rRelId ); }
221 // Set font color only for extdrawings.
222 void setFontRefColorForNodes(const Color& rColor) { maFontRefColorForNodes = rColor; }
223 const Color& getFontRefColorForNodes() const { return maFontRefColorForNodes; }
224 void setLockedCanvas(bool bLockedCanvas);
225 bool getLockedCanvas() const { return mbLockedCanvas;}
226 void setWPGChild(bool bWPG);
227 bool isWPGChild() const { return mbWPGChild;}
228 void setWps(bool bWps);
229 bool getWps() const { return mbWps;}
230 void setTextBox(bool bTextBox);
231 const css::uno::Sequence<css::beans::PropertyValue> &
232 getDiagramDoms() const { return maDiagramDoms; }
233 void setDiagramDoms(const css::uno::Sequence<css::beans::PropertyValue>& rDiagramDoms) { maDiagramDoms = rDiagramDoms; }
234 css::uno::Sequence< css::uno::Sequence< css::uno::Any > >resolveRelationshipsOfTypeFromOfficeDoc(
235 core::XmlFilterBase& rFilter, const OUString& sFragment, std::u16string_view sType );
236 void setLinkedTxbxAttributes(const LinkedTxbxAttr& rhs){ maLinkedTxbxAttr = rhs; };
237 void setTxbxHasLinkedTxtBox( const bool rhs){ mbHasLinkedTxbx = rhs; };
238 const LinkedTxbxAttr& getLinkedTxbxAttributes() const { return maLinkedTxbxAttr; };
239 bool isLinkedTxbx() const { return mbHasLinkedTxbx; };
241 void setZOrder(sal_Int32 nZOrder) { mnZOrder = nZOrder; }
243 sal_Int32 getZOrder() const { return mnZOrder; }
245 void setZOrderOff(sal_Int32 nZOrderOff) { mnZOrderOff = nZOrderOff; }
247 sal_Int32 getZOrderOff() const { return mnZOrderOff; }
249 void setDataNodeType(sal_Int32 nDataNodeType) { mnDataNodeType = nDataNodeType; }
251 sal_Int32 getDataNodeType() const { return mnDataNodeType; }
253 void setAspectRatio(double fAspectRatio) { mfAspectRatio = fAspectRatio; }
255 double getAspectRatio() const { return mfAspectRatio; }
257 void setVerticalShapesCount(sal_Int32 nVerticalShapesCount) { mnVerticalShapesCount = nVerticalShapesCount; }
258 sal_Int32 getVerticalShapesCount() const { return mnVerticalShapesCount; }
260 /// Changes reference semantics to value semantics for fill properties.
261 void cloneFillProperties();
263 void keepDiagramDrawing(::oox::core::XmlFilterBase& rFilterBase, const OUString& rFragmentPath);
265 // Allows preparation of a local Diagram helper && propagate an eventually
266 // existing one to the data holder object later
267 void prepareDiagramHelper(const std::shared_ptr< Diagram >& rDiagramPtr, const std::shared_ptr<::oox::drawingml::Theme>& rTheme);
268 void propagateDiagramHelper();
270 // for Writer it is necessary to migrate an existing helper to a new Shape
271 void migrateDiagramHelperToNewShape(const ShapePtr& pTarget);
273 protected:
275 enum FrameType
277 FRAMETYPE_GENERIC, ///< Generic shape, no special type.
278 FRAMETYPE_OLEOBJECT, ///< OLE object embedded in a shape.
279 FRAMETYPE_CHART, ///< Chart embedded in a shape.
280 FRAMETYPE_DIAGRAM, ///< Complex diagram drawing shape.
281 FRAMETYPE_TABLE ///< A table embedded in a shape.
284 css::uno::Reference< css::drawing::XShape > const &
285 createAndInsert(
286 ::oox::core::XmlFilterBase& rFilterBase,
287 const OUString& rServiceName,
288 const Theme* pTheme,
289 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
290 bool bClearText,
291 bool bDoNotInsertEmptyTextBody,
292 basegfx::B2DHomMatrix& aTransformation,
293 const FillProperties& rShapeOrParentShapeFillProps,
294 oox::drawingml::ShapePtr pParentGroupShape = nullptr
297 void addChildren(
298 ::oox::core::XmlFilterBase& rFilterBase,
299 Shape& rMaster,
300 const Theme* pTheme,
301 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
302 ShapeIdMap* pShapeMap,
303 const basegfx::B2DHomMatrix& aTransformation );
305 void keepDiagramCompatibilityInfo();
306 void convertSmartArtToMetafile( ::oox::core::XmlFilterBase const& rFilterBase );
308 css::uno::Reference< css::drawing::XShape >
309 renderDiagramToGraphic( ::oox::core::XmlFilterBase const & rFilterBase );
311 OUString finalizeServiceName(
312 ::oox::core::XmlFilterBase& rFilter,
313 const OUString& rServiceName,
314 const css::awt::Rectangle& rShapeRect );
316 virtual void finalizeXShape(
317 ::oox::core::XmlFilterBase& rFilter,
318 const css::uno::Reference< css::drawing::XShapes >& rxShapes );
320 void putPropertyToGrabBag(
321 const OUString& sPropertyName, const css::uno::Any& aPropertyValue );
322 void putPropertyToGrabBag(
323 const css::beans::PropertyValue& pProperty );
324 void putPropertiesToGrabBag(
325 const css::uno::Sequence< css::beans::PropertyValue >& aProperties );
327 FillProperties getActualFillProperties(const Theme* pTheme, const FillProperties* pParentShapeFillProps) const;
328 LineProperties getActualLineProperties(const Theme* pTheme) const;
329 EffectProperties getActualEffectProperties(const Theme* pTheme) const;
331 std::vector< ShapePtr > maChildren; // only used for group shapes
332 css::awt::Size maChSize; // only used for group shapes
333 css::awt::Point maChPosition; // only used for group shapes
335 std::vector<OUString> maConnectorAdjustmentList; // only used for connector shapes
337 TextBodyPtr mpTextBody;
338 LinePropertiesPtr mpLinePropertiesPtr;
339 LinePropertiesPtr mpShapeRefLinePropPtr;
340 FillPropertiesPtr mpFillPropertiesPtr;
341 FillPropertiesPtr mpShapeRefFillPropPtr;
342 GraphicPropertiesPtr mpGraphicPropertiesPtr;
343 CustomShapePropertiesPtr mpCustomShapePropertiesPtr;
344 table::TablePropertiesPtr mpTablePropertiesPtr;
345 Shape3DPropertiesPtr mp3DPropertiesPtr;
346 EffectPropertiesPtr mpEffectPropertiesPtr;
347 EffectPropertiesPtr mpShapeRefEffectPropPtr;
348 PropertyMap maShapeProperties;
349 PropertyMap maDefaultShapeProperties;
350 TextListStylePtr mpMasterTextListStyle;
351 css::uno::Reference< css::drawing::XShape > mxShape;
352 ConnectorShapePropertiesList maConnectorShapePropertiesList;
354 OUString msConnectorName;
355 OUString msServiceName;
356 OUString msName;
357 OUString msInternalName; // used by diagram; not displayed in UI
358 OUString msId;
359 OUString msDescription;
360 bool m_isDecorative = false;
361 sal_Int32 mnSubType; // if this type is not zero, then the shape is a placeholder
362 std::optional< sal_Int32 > moSubTypeIndex;
364 ShapeStyleRefMap maShapeStyleRefs;
366 css::awt::Size maSize;
367 css::awt::Point maPosition;
368 ::std::vector<OUString> maExtDrawings;
369 Color maFontRefColorForNodes;
371 FrameType meFrameType; ///< Type for graphic frame shapes.
373 private:
375 typedef std::shared_ptr< ::oox::vml::OleObjectInfo > OleObjectInfoRef;
376 typedef std::shared_ptr< ChartShapeInfo > ChartShapeInfoRef;
378 OleObjectInfoRef mxOleObjectInfo; ///< Additional data for OLE objects.
379 ChartShapeInfoRef mxChartShapeInfo; ///< Additional data for chart shapes.
381 sal_Int32 mnRotation;
382 sal_Int32 mnDiagramRotation; // rotates shape prior to sizing, does not affect text rotation
383 bool mbFlipH;
384 bool mbFlipV;
385 bool mbHidden;
386 bool mbHiddenMasterShape; // master shapes can be hidden in layout slides
387 // we need separate flag because we don't want
388 // to propagate it when applying reference shape
389 bool mbLocked;
390 bool mbWPGChild; // Is this shape a child of a WPG shape?
391 bool mbLockedCanvas; ///< Is this shape part of a locked canvas?
392 bool mbWps; ///< Is this a wps shape?
393 bool mbTextBox; ///< This shape has a textbox.
394 LinkedTxbxAttr maLinkedTxbxAttr;
395 bool mbHasLinkedTxbx; // this text box has linked text box ?
397 css::uno::Sequence<css::beans::PropertyValue> maDiagramDoms;
399 /// Z-Order.
400 sal_Int32 mnZOrder = 0;
402 /// Z-Order offset.
403 sal_Int32 mnZOrderOff = 0;
405 /// Type of data node for an in-diagram shape.
406 sal_Int32 mnDataNodeType = 0;
408 /// Aspect ratio for an in-diagram shape.
409 double mfAspectRatio = 0;
411 /// Number of child shapes to be layouted vertically inside org chart in-diagram shape.
412 sal_Int32 mnVerticalShapesCount = 0;
414 // Is this a connector shape?
415 bool mbConnector = false;
417 // temporary space for DiagramHelper in preparation for collecting data
418 // Note: I tried to use a unique_ptr here, but existing constructor func does not allow that
419 svx::diagram::IDiagramHelper* mpDiagramHelper;
421 // association-ID to identify the Diagram ModelData
422 OUString msDiagramDataModelID;
427 #endif // INCLUDED_OOX_DRAWINGML_SHAPE_HXX
429 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */