Avoid potential negative array index access to cached text.
[LibreOffice.git] / include / oox / drawingml / shape.hxx
blobb5dad22b64afcf3ba6f870d3ca29482d02beca39
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/propertymap.hxx>
40 #include <rtl/ustring.hxx>
41 #include <sal/types.h>
43 namespace basegfx { class B2DHomMatrix; }
45 namespace com::sun::star {
46 namespace awt { struct Rectangle; }
47 namespace drawing { class XShape; }
48 namespace drawing { class XShapes; }
49 namespace uno { class Any; }
52 namespace oox::core {
53 class XmlFilterBase;
56 namespace oox::vml {
57 struct OleObjectInfo;
60 namespace svx::diagram {
61 class IDiagramHelper;
64 namespace oox::drawingml {
66 class Theme;
67 struct EffectProperties;
68 struct FillProperties;
69 struct GraphicProperties;
70 struct LineProperties;
71 struct Shape3DProperties;
72 class AdvancedDiagramHelper;
73 class CustomShapeProperties;
74 typedef std::shared_ptr< CustomShapeProperties > CustomShapePropertiesPtr;
76 typedef ::std::map< OUString, ShapePtr > ShapeIdMap;
78 typedef std::vector<ConnectorShapeProperties> ConnectorShapePropertiesList;
80 struct ShapeStyleRef
82 Color maPhClr;
83 sal_Int32 mnThemedIdx;
84 ShapeStyleRef() : mnThemedIdx(0) {}
87 typedef ::std::map< sal_Int32, ShapeStyleRef > ShapeStyleRefMap;
89 /** Additional information for a chart embedded in a drawing shape. */
90 struct ChartShapeInfo
92 OUString maFragmentPath; ///< Path to related XML stream, e.g. for charts.
93 bool mbEmbedShapes; ///< True = load chart shapes into chart, false = load into parent drawpage.
95 explicit ChartShapeInfo( bool bEmbedShapes ) : mbEmbedShapes( bEmbedShapes ) {}
98 /// Attributes for a linked textbox.
99 struct LinkedTxbxAttr
101 sal_Int32 id;
102 sal_Int32 seq;
103 LinkedTxbxAttr(): id(0),seq(0){};
106 class Diagram;
108 class OOX_DLLPUBLIC Shape
109 : public std::enable_shared_from_this< Shape >
111 public:
113 explicit Shape( const char* pServiceType = nullptr, bool bDefaultHeight = true );
114 explicit Shape( const ShapePtr& pSourceShape );
115 Shape(Shape const &) = default;
116 virtual ~Shape();
117 Shape & operator =(Shape const &) = default;
119 OUString& getServiceName(){ return msServiceName; }
120 void setServiceName( const char* pServiceName );
122 const OUString& getDiagramDataModelID() const { return msDiagramDataModelID; }
123 void setDiagramDataModelID( const OUString& rDiagramDataModelID ) { msDiagramDataModelID = rDiagramDataModelID; }
125 PropertyMap& getShapeProperties(){ return maShapeProperties; }
127 LineProperties& getLineProperties() { return *mpLinePropertiesPtr; }
128 const LineProperties& getLineProperties() const { return *mpLinePropertiesPtr; }
130 FillProperties& getFillProperties() { return *mpFillPropertiesPtr; }
131 const FillProperties& getFillProperties() const { return *mpFillPropertiesPtr; }
133 GraphicProperties& getGraphicProperties() { return *mpGraphicPropertiesPtr; }
134 const GraphicProperties& getGraphicProperties() const { return *mpGraphicPropertiesPtr; }
136 CustomShapePropertiesPtr& getCustomShapeProperties(){ return mpCustomShapePropertiesPtr; }
138 OUString& getConnectorName() { return msConnectorName; }
139 std::vector<OUString>& getConnectorAdjustments() { return maConnectorAdjustmentList; };
140 ConnectorShapePropertiesList& getConnectorShapeProperties() { return maConnectorShapePropertiesList; }
141 void setConnectorShape(bool bConnector) { mbConnector = bConnector; }
142 bool isConnectorShape() const { return mbConnector; }
144 Shape3DProperties& get3DProperties() { return *mp3DPropertiesPtr; }
145 const Shape3DProperties& get3DProperties() const { return *mp3DPropertiesPtr; }
147 table::TablePropertiesPtr const & getTableProperties();
149 EffectProperties& getEffectProperties() const { return *mpEffectPropertiesPtr; }
151 void setChildPosition( css::awt::Point nPosition ){ maChPosition = nPosition; }
152 void setChildSize( css::awt::Size aSize ){ maChSize = aSize; }
154 void setPosition( css::awt::Point nPosition ){ maPosition = nPosition; }
155 const css::awt::Point& getPosition() const { return maPosition; }
157 void setSize( css::awt::Size aSize ){ maSize = aSize; }
158 const css::awt::Size& getSize() const { return maSize; }
160 void setRotation( sal_Int32 nRotation ) { mnRotation = nRotation; }
161 sal_Int32 getRotation() const { return mnRotation; }
162 void setDiagramRotation( sal_Int32 nRotation ) { mnDiagramRotation = nRotation; }
163 void setFlip( bool bFlipH, bool bFlipV ) { mbFlipH = bFlipH; mbFlipV = bFlipV; }
164 bool getFlipH() const { return mbFlipH; }
165 bool getFlipV() const { return mbFlipV; }
166 void addChild( const ShapePtr& rChildPtr ) { maChildren.push_back( rChildPtr ); }
167 std::vector< ShapePtr >& getChildren() { return maChildren; }
169 void setName( const OUString& rName ) { msName = rName; }
170 const OUString& getName( ) const { return msName; }
171 void setInternalName( const OUString& rInternalName ) { msInternalName = rInternalName; }
172 const OUString& getInternalName() const { return msInternalName; }
173 void setId( const OUString& rId ) { msId = rId; }
174 const OUString& getId() const { return msId; }
175 void setDescription( const OUString& rDescr ) { msDescription = rDescr; }
176 void setDecorative(bool const isDecorative) { m_isDecorative = isDecorative; }
177 void setHidden( bool bHidden ) { mbHidden = bHidden; }
178 void setHiddenMasterShape( bool bHiddenMasterShape ) { mbHiddenMasterShape = bHiddenMasterShape; }
179 void setLocked( bool bLocked ) { mbLocked = bLocked; }
180 void setSubType( sal_Int32 nSubType ) { mnSubType = nSubType; }
181 sal_Int32 getSubType() const { return mnSubType; }
182 void setSubTypeIndex( sal_Int32 nSubTypeIndex ) { moSubTypeIndex = nSubTypeIndex; }
183 const std::optional< sal_Int32 >& getSubTypeIndex() const { return moSubTypeIndex; }
185 // setDefaults has to be called if styles are imported (OfficeXML is not storing properties having the default value)
186 void setDefaults(bool bHeight);
188 ::oox::vml::OleObjectInfo& setOleObjectType();
189 ChartShapeInfo& setChartType( bool bEmbedShapes );
190 void setDiagramType();
191 void setTableType();
193 void setTextBody(const TextBodyPtr & pTextBody);
194 const TextBodyPtr& getTextBody() const { return mpTextBody;}
195 void setMasterTextListStyle( const TextListStylePtr& pMasterTextListStyle );
196 const TextListStylePtr& getMasterTextListStyle() const { return mpMasterTextListStyle; }
198 ShapeStyleRefMap& getShapeStyleRefs() { return maShapeStyleRefs; }
199 const ShapeStyleRefMap& getShapeStyleRefs() const { return maShapeStyleRefs; }
200 const ShapeStyleRef* getShapeStyleRef( sal_Int32 nRefType ) const;
201 bool hasShapeStyleRefs() const { return !maShapeStyleRefs.empty(); }
203 // addShape is creating and inserting the corresponding XShape.
204 void addShape(
205 ::oox::core::XmlFilterBase& rFilterBase,
206 const Theme* pTheme,
207 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
208 const basegfx::B2DHomMatrix& aTransformation,
209 const FillProperties& rShapeOrParentShapeFillProps,
210 ShapeIdMap* pShapeMap = nullptr,
211 oox::drawingml::ShapePtr pParentGroupShape = nullptr);
213 const css::uno::Reference< css::drawing::XShape > &
214 getXShape() const { return mxShape; }
216 void applyShapeReference( const Shape& rReferencedShape, bool bUseText = true );
217 const ::std::vector<OUString>&
218 getExtDrawings() const { return maExtDrawings; }
219 void addExtDrawingRelId( const OUString &rRelId ) { maExtDrawings.push_back( rRelId ); }
220 // Set font color only for extdrawings.
221 void setFontRefColorForNodes(const Color& rColor) { maFontRefColorForNodes = rColor; }
222 const Color& getFontRefColorForNodes() const { return maFontRefColorForNodes; }
223 void setLockedCanvas(bool bLockedCanvas);
224 bool getLockedCanvas() const { return mbLockedCanvas;}
225 void setWordprocessingCanvas(bool bWordprocessingCanvas);
226 bool isInWordprocessingCanvas() const {return mbWordprocessingCanvas;}
227 void setWPGChild(bool bWPG);
228 bool isWPGChild() const { return mbWPGChild;}
229 void setWps(bool bWps);
230 bool getWps() const { return mbWps;}
231 void setTextBox(bool bTextBox);
232 const css::uno::Sequence<css::beans::PropertyValue> &
233 getDiagramDoms() const { return maDiagramDoms; }
234 void setDiagramDoms(const css::uno::Sequence<css::beans::PropertyValue>& rDiagramDoms) { maDiagramDoms = rDiagramDoms; }
235 css::uno::Sequence< css::uno::Sequence< css::uno::Any > >resolveRelationshipsOfTypeFromOfficeDoc(
236 core::XmlFilterBase& rFilter, const OUString& sFragment, std::u16string_view sType );
237 void setLinkedTxbxAttributes(const LinkedTxbxAttr& rhs){ maLinkedTxbxAttr = rhs; };
238 void setTxbxHasLinkedTxtBox( const bool rhs){ mbHasLinkedTxbx = rhs; };
239 const LinkedTxbxAttr& getLinkedTxbxAttributes() const { return maLinkedTxbxAttr; };
240 bool isLinkedTxbx() const { return mbHasLinkedTxbx; };
242 void setZOrder(sal_Int32 nZOrder) { mnZOrder = nZOrder; }
244 sal_Int32 getZOrder() const { return mnZOrder; }
246 void setZOrderOff(sal_Int32 nZOrderOff) { mnZOrderOff = nZOrderOff; }
248 sal_Int32 getZOrderOff() const { return mnZOrderOff; }
250 void setDataNodeType(sal_Int32 nDataNodeType) { mnDataNodeType = nDataNodeType; }
252 sal_Int32 getDataNodeType() const { return mnDataNodeType; }
254 void setAspectRatio(double fAspectRatio) { mfAspectRatio = fAspectRatio; }
256 double getAspectRatio() const { return mfAspectRatio; }
258 void setVerticalShapesCount(sal_Int32 nVerticalShapesCount) { mnVerticalShapesCount = nVerticalShapesCount; }
259 sal_Int32 getVerticalShapesCount() const { return mnVerticalShapesCount; }
261 /// Changes reference semantics to value semantics for fill properties.
262 void cloneFillProperties();
264 void keepDiagramDrawing(::oox::core::XmlFilterBase& rFilterBase, const OUString& rFragmentPath);
266 // Allows preparation of a local Diagram helper && propagate an eventually
267 // existing one to the data holder object later
268 void prepareDiagramHelper(const std::shared_ptr< Diagram >& rDiagramPtr, const std::shared_ptr<::oox::drawingml::Theme>& rTheme);
269 void propagateDiagramHelper();
271 // for Writer it is necessary to migrate an existing helper to a new Shape
272 void migrateDiagramHelperToNewShape(const ShapePtr& pTarget);
274 protected:
276 enum FrameType
278 FRAMETYPE_GENERIC, ///< Generic shape, no special type.
279 FRAMETYPE_OLEOBJECT, ///< OLE object embedded in a shape.
280 FRAMETYPE_CHART, ///< Chart embedded in a shape.
281 FRAMETYPE_DIAGRAM, ///< Complex diagram drawing shape.
282 FRAMETYPE_TABLE ///< A table embedded in a shape.
285 css::uno::Reference< css::drawing::XShape > const &
286 createAndInsert(
287 ::oox::core::XmlFilterBase& rFilterBase,
288 const OUString& rServiceName,
289 const Theme* pTheme,
290 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
291 bool bClearText,
292 bool bDoNotInsertEmptyTextBody,
293 basegfx::B2DHomMatrix& aTransformation,
294 const FillProperties& rShapeOrParentShapeFillProps,
295 oox::drawingml::ShapePtr pParentGroupShape = nullptr
298 void addChildren(
299 ::oox::core::XmlFilterBase& rFilterBase,
300 Shape& rMaster,
301 const Theme* pTheme,
302 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
303 ShapeIdMap* pShapeMap,
304 const basegfx::B2DHomMatrix& aTransformation );
306 void keepDiagramCompatibilityInfo();
307 void convertSmartArtToMetafile( ::oox::core::XmlFilterBase const& rFilterBase );
309 css::uno::Reference< css::drawing::XShape >
310 renderDiagramToGraphic( ::oox::core::XmlFilterBase const & rFilterBase );
312 OUString finalizeServiceName(
313 ::oox::core::XmlFilterBase& rFilter,
314 const OUString& rServiceName,
315 const css::awt::Rectangle& rShapeRect );
317 virtual void finalizeXShape(
318 ::oox::core::XmlFilterBase& rFilter,
319 const css::uno::Reference< css::drawing::XShapes >& rxShapes );
321 void putPropertyToGrabBag(
322 const OUString& sPropertyName, const css::uno::Any& aPropertyValue );
323 void putPropertyToGrabBag(
324 const css::beans::PropertyValue& pProperty );
325 void putPropertiesToGrabBag(
326 const css::uno::Sequence< css::beans::PropertyValue >& aProperties );
328 FillProperties getActualFillProperties(const Theme* pTheme, const FillProperties* pParentShapeFillProps) const;
329 LineProperties getActualLineProperties(const Theme* pTheme) const;
330 EffectProperties getActualEffectProperties(const Theme* pTheme) const;
332 std::vector< ShapePtr > maChildren; // only used for group shapes
333 css::awt::Size maChSize; // only used for group shapes
334 css::awt::Point maChPosition; // only used for group shapes
336 std::vector<OUString> maConnectorAdjustmentList; // only used for connector shapes
338 TextBodyPtr mpTextBody;
339 LinePropertiesPtr mpLinePropertiesPtr;
340 LinePropertiesPtr mpShapeRefLinePropPtr;
341 FillPropertiesPtr mpFillPropertiesPtr;
342 FillPropertiesPtr mpShapeRefFillPropPtr;
343 GraphicPropertiesPtr mpGraphicPropertiesPtr;
344 CustomShapePropertiesPtr mpCustomShapePropertiesPtr;
345 table::TablePropertiesPtr mpTablePropertiesPtr;
346 Shape3DPropertiesPtr mp3DPropertiesPtr;
347 EffectPropertiesPtr mpEffectPropertiesPtr;
348 EffectPropertiesPtr mpShapeRefEffectPropPtr;
349 PropertyMap maShapeProperties;
350 PropertyMap maDefaultShapeProperties;
351 TextListStylePtr mpMasterTextListStyle;
352 css::uno::Reference< css::drawing::XShape > mxShape;
353 ConnectorShapePropertiesList maConnectorShapePropertiesList;
355 OUString msConnectorName;
356 OUString msServiceName;
357 OUString msName;
358 OUString msInternalName; // used by diagram; not displayed in UI
359 OUString msId;
360 OUString msDescription;
361 bool m_isDecorative = false;
362 sal_Int32 mnSubType; // if this type is not zero, then the shape is a placeholder
363 std::optional< sal_Int32 > moSubTypeIndex;
365 ShapeStyleRefMap maShapeStyleRefs;
367 css::awt::Size maSize;
368 css::awt::Point maPosition;
369 ::std::vector<OUString> maExtDrawings;
370 Color maFontRefColorForNodes;
372 FrameType meFrameType; ///< Type for graphic frame shapes.
374 private:
376 typedef std::shared_ptr< ::oox::vml::OleObjectInfo > OleObjectInfoRef;
377 typedef std::shared_ptr< ChartShapeInfo > ChartShapeInfoRef;
379 OleObjectInfoRef mxOleObjectInfo; ///< Additional data for OLE objects.
380 ChartShapeInfoRef mxChartShapeInfo; ///< Additional data for chart shapes.
382 sal_Int32 mnRotation;
383 sal_Int32 mnDiagramRotation; // rotates shape prior to sizing, does not affect text rotation
384 bool mbFlipH;
385 bool mbFlipV;
386 bool mbHidden;
387 bool mbHiddenMasterShape; // master shapes can be hidden in layout slides
388 // we need separate flag because we don't want
389 // to propagate it when applying reference shape
390 bool mbLocked;
391 bool mbWPGChild; // Is this shape a child of a WPG shape?
392 bool mbLockedCanvas; ///< Is this shape part of a locked canvas?
393 bool mbWordprocessingCanvas; ///< Is this shape part of a wordprocessing canvas?
394 bool mbWps; ///< Is this a wps shape?
395 bool mbTextBox; ///< This shape has a textbox.
396 LinkedTxbxAttr maLinkedTxbxAttr;
397 bool mbHasLinkedTxbx; // this text box has linked text box ?
399 css::uno::Sequence<css::beans::PropertyValue> maDiagramDoms;
401 /// Z-Order.
402 sal_Int32 mnZOrder = 0;
404 /// Z-Order offset.
405 sal_Int32 mnZOrderOff = 0;
407 /// Type of data node for an in-diagram shape.
408 sal_Int32 mnDataNodeType = 0;
410 /// Aspect ratio for an in-diagram shape.
411 double mfAspectRatio = 0;
413 /// Number of child shapes to be layouted vertically inside org chart in-diagram shape.
414 sal_Int32 mnVerticalShapesCount = 0;
416 // Is this a connector shape?
417 bool mbConnector = false;
419 // temporary space for DiagramHelper in preparation for collecting data
420 // Note: I tried to use a unique_ptr here, but existing constructor func does not allow that
421 AdvancedDiagramHelper* mpDiagramHelper;
423 // association-ID to identify the Diagram ModelData
424 OUString msDiagramDataModelID;
429 #endif // INCLUDED_OOX_DRAWINGML_SHAPE_HXX
431 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */