tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / include / oox / drawingml / shape.hxx
blob81797757faaf87d06d6678d8c274305be3f8a64b
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 Shape();
114 explicit Shape( const OUString& rServiceType, bool bDefaultHeight = true );
115 SAL_DLLPRIVATE explicit Shape( const ShapePtr& pSourceShape );
116 Shape(Shape const &) = default;
117 virtual ~Shape();
118 Shape & operator =(Shape const &) = default;
120 const OUString& getServiceName() const { return msServiceName; }
121 void setServiceName( const OUString& rServiceName ) { msServiceName = rServiceName; }
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 SAL_DLLPRIVATE 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 setMacro(const OUString& rMacro) { msMacro = rMacro; }
179 void setTextLinkAttr(const OUString& rTextLink) { msTextLink = rTextLink; }
180 void setFLocksText(bool bFLocksText) { mbFLocksText = bFLocksText; }
181 void setFPublished(bool bFPublished) { mbFPublished = bFPublished; }
182 void setTitle(const OUString& rTitle) { msTitle = rTitle; }
183 void setHidden( bool bHidden ) { mbHidden = bHidden; }
184 void setHiddenMasterShape( bool bHiddenMasterShape ) { mbHiddenMasterShape = bHiddenMasterShape; }
185 void setLocked( bool bLocked ) { mbLocked = bLocked; }
186 void setSubType( sal_Int32 nSubType ) { mnSubType = nSubType; }
187 sal_Int32 getSubType() const { return mnSubType; }
188 void setSubTypeIndex( sal_Int32 nSubTypeIndex ) { moSubTypeIndex = nSubTypeIndex; }
189 const std::optional< sal_Int32 >& getSubTypeIndex() const { return moSubTypeIndex; }
191 // setDefaults has to be called if styles are imported (OfficeXML is not storing properties having the default value)
192 SAL_DLLPRIVATE void setDefaults(bool bHeight);
194 SAL_DLLPRIVATE ::oox::vml::OleObjectInfo& setOleObjectType();
195 SAL_DLLPRIVATE ChartShapeInfo& setChartType( bool bEmbedShapes );
196 SAL_DLLPRIVATE void setDiagramType();
197 SAL_DLLPRIVATE void setTableType();
199 SAL_DLLPRIVATE void setTextBody(const TextBodyPtr & pTextBody);
200 const TextBodyPtr& getTextBody() const { return mpTextBody;}
201 SAL_DLLPRIVATE void setMasterTextListStyle( const TextListStylePtr& pMasterTextListStyle );
202 const TextListStylePtr& getMasterTextListStyle() const { return mpMasterTextListStyle; }
204 SAL_DLLPRIVATE ShapeStyleRefMap& getShapeStyleRefs() { return maShapeStyleRefs; }
205 const ShapeStyleRefMap& getShapeStyleRefs() const { return maShapeStyleRefs; }
206 const ShapeStyleRef* getShapeStyleRef( sal_Int32 nRefType ) const;
207 bool hasShapeStyleRefs() const { return !maShapeStyleRefs.empty(); }
209 // addShape is creating and inserting the corresponding XShape.
210 void addShape(
211 ::oox::core::XmlFilterBase& rFilterBase,
212 const Theme* pTheme,
213 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
214 const basegfx::B2DHomMatrix& aTransformation,
215 const FillProperties& rShapeOrParentShapeFillProps,
216 ShapeIdMap* pShapeMap = nullptr,
217 const oox::drawingml::ShapePtr& pParentGroupShape = nullptr);
219 const css::uno::Reference< css::drawing::XShape > &
220 getXShape() const { return mxShape; }
222 SAL_DLLPRIVATE void applyShapeReference( const Shape& rReferencedShape, bool bUseText = true );
223 const ::std::vector<OUString>&
224 getExtDrawings() const { return maExtDrawings; }
225 void addExtDrawingRelId( const OUString &rRelId ) { maExtDrawings.push_back( rRelId ); }
226 // Set font color only for extdrawings.
227 void setFontRefColorForNodes(const Color& rColor) { maFontRefColorForNodes = rColor; }
228 const Color& getFontRefColorForNodes() const { return maFontRefColorForNodes; }
229 SAL_DLLPRIVATE void setLockedCanvas(bool bLockedCanvas);
230 bool getLockedCanvas() const { return mbLockedCanvas;}
231 SAL_DLLPRIVATE void setWordprocessingCanvas(bool bWordprocessingCanvas);
232 bool isInWordprocessingCanvas() const {return mbWordprocessingCanvas;}
233 SAL_DLLPRIVATE void setWPGChild(bool bWPG);
234 bool isWPGChild() const { return mbWPGChild;}
235 SAL_DLLPRIVATE void setWps(bool bWps);
236 bool getWps() const { return mbWps;}
237 SAL_DLLPRIVATE void setTextBox(bool bTextBox);
238 const css::uno::Sequence<css::beans::PropertyValue> &
239 getDiagramDoms() const { return maDiagramDoms; }
240 void setDiagramDoms(const css::uno::Sequence<css::beans::PropertyValue>& rDiagramDoms) { maDiagramDoms = rDiagramDoms; }
241 SAL_DLLPRIVATE css::uno::Sequence< css::uno::Sequence< css::uno::Any > >resolveRelationshipsOfTypeFromOfficeDoc(
242 core::XmlFilterBase& rFilter, const OUString& sFragment, std::u16string_view sType );
243 void setLinkedTxbxAttributes(const LinkedTxbxAttr& rhs){ maLinkedTxbxAttr = rhs; };
244 void setTxbxHasLinkedTxtBox( const bool rhs){ mbHasLinkedTxbx = rhs; };
245 const LinkedTxbxAttr& getLinkedTxbxAttributes() const { return maLinkedTxbxAttr; };
246 bool isLinkedTxbx() const { return mbHasLinkedTxbx; };
248 void setZOrder(sal_Int32 nZOrder) { mnZOrder = nZOrder; }
250 sal_Int32 getZOrder() const { return mnZOrder; }
252 void setZOrderOff(sal_Int32 nZOrderOff) { mnZOrderOff = nZOrderOff; }
254 sal_Int32 getZOrderOff() const { return mnZOrderOff; }
256 void setDataNodeType(sal_Int32 nDataNodeType) { mnDataNodeType = nDataNodeType; }
258 sal_Int32 getDataNodeType() const { return mnDataNodeType; }
260 void setAspectRatio(double fAspectRatio) { mfAspectRatio = fAspectRatio; }
262 double getAspectRatio() const { return mfAspectRatio; }
264 void setVerticalShapesCount(sal_Int32 nVerticalShapesCount) { mnVerticalShapesCount = nVerticalShapesCount; }
265 sal_Int32 getVerticalShapesCount() const { return mnVerticalShapesCount; }
267 /// Changes reference semantics to value semantics for fill properties.
268 SAL_DLLPRIVATE void cloneFillProperties();
270 SAL_DLLPRIVATE void keepDiagramDrawing(::oox::core::XmlFilterBase& rFilterBase, const OUString& rFragmentPath);
272 // Allows preparation of a local Diagram helper && propagate an eventually
273 // existing one to the data holder object later
274 SAL_DLLPRIVATE void prepareDiagramHelper(
275 const std::shared_ptr< Diagram >& rDiagramPtr,
276 const std::shared_ptr<::oox::drawingml::Theme>& rTheme,
277 bool bSelfCreated);
278 SAL_DLLPRIVATE void propagateDiagramHelper();
280 // for Writer it is necessary to migrate an existing helper to a new Shape
281 SAL_DLLPRIVATE void migrateDiagramHelperToNewShape(const ShapePtr& pTarget);
283 protected:
285 enum FrameType
287 FRAMETYPE_GENERIC, ///< Generic shape, no special type.
288 FRAMETYPE_OLEOBJECT, ///< OLE object embedded in a shape.
289 FRAMETYPE_CHART, ///< Chart embedded in a shape.
290 FRAMETYPE_DIAGRAM, ///< Complex diagram drawing shape.
291 FRAMETYPE_TABLE ///< A table embedded in a shape.
294 SAL_DLLPRIVATE css::uno::Reference< css::drawing::XShape > const &
295 createAndInsert(
296 ::oox::core::XmlFilterBase& rFilterBase,
297 const OUString& rServiceName,
298 const Theme* pTheme,
299 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
300 bool bClearText,
301 bool bDoNotInsertEmptyTextBody,
302 basegfx::B2DHomMatrix& aTransformation,
303 const FillProperties& rShapeOrParentShapeFillProps,
304 const oox::drawingml::ShapePtr& pParentGroupShape = nullptr
307 SAL_DLLPRIVATE void addChildren(
308 ::oox::core::XmlFilterBase& rFilterBase,
309 Shape& rMaster,
310 const Theme* pTheme,
311 const css::uno::Reference< css::drawing::XShapes >& rxShapes,
312 ShapeIdMap* pShapeMap,
313 const basegfx::B2DHomMatrix& aTransformation );
315 SAL_DLLPRIVATE void keepDiagramCompatibilityInfo();
316 SAL_DLLPRIVATE void convertSmartArtToMetafile( ::oox::core::XmlFilterBase const& rFilterBase );
318 SAL_DLLPRIVATE css::uno::Reference< css::drawing::XShape >
319 renderDiagramToGraphic( ::oox::core::XmlFilterBase const & rFilterBase );
321 SAL_DLLPRIVATE OUString finalizeServiceName(
322 ::oox::core::XmlFilterBase& rFilter,
323 const OUString& rServiceName,
324 const css::awt::Rectangle& rShapeRect );
326 virtual void finalizeXShape(
327 ::oox::core::XmlFilterBase& rFilter,
328 const css::uno::Reference< css::drawing::XShapes >& rxShapes );
330 SAL_DLLPRIVATE void putPropertyToGrabBag(
331 const OUString& sPropertyName, const css::uno::Any& aPropertyValue );
332 SAL_DLLPRIVATE void putPropertyToGrabBag(
333 const css::beans::PropertyValue& pProperty );
334 SAL_DLLPRIVATE void putPropertiesToGrabBag(
335 const css::uno::Sequence< css::beans::PropertyValue >& aProperties );
337 SAL_DLLPRIVATE FillProperties getActualFillProperties(const Theme* pTheme, const FillProperties* pParentShapeFillProps) const;
338 SAL_DLLPRIVATE LineProperties getActualLineProperties(const Theme* pTheme) const;
339 SAL_DLLPRIVATE EffectProperties getActualEffectProperties(const Theme* pTheme) const;
341 std::vector< ShapePtr > maChildren; // only used for group shapes
342 css::awt::Size maChSize; // only used for group shapes
343 css::awt::Point maChPosition; // only used for group shapes
345 std::vector<OUString> maConnectorAdjustmentList; // only used for connector shapes
347 TextBodyPtr mpTextBody;
348 LinePropertiesPtr mpLinePropertiesPtr;
349 LinePropertiesPtr mpShapeRefLinePropPtr;
350 FillPropertiesPtr mpFillPropertiesPtr;
351 FillPropertiesPtr mpShapeRefFillPropPtr;
352 GraphicPropertiesPtr mpGraphicPropertiesPtr;
353 CustomShapePropertiesPtr mpCustomShapePropertiesPtr;
354 table::TablePropertiesPtr mpTablePropertiesPtr;
355 Shape3DPropertiesPtr mp3DPropertiesPtr;
356 EffectPropertiesPtr mpEffectPropertiesPtr;
357 EffectPropertiesPtr mpShapeRefEffectPropPtr;
358 PropertyMap maShapeProperties;
359 PropertyMap maDefaultShapeProperties;
360 TextListStylePtr mpMasterTextListStyle;
361 css::uno::Reference< css::drawing::XShape > mxShape;
362 ConnectorShapePropertiesList maConnectorShapePropertiesList;
364 OUString msConnectorName;
365 OUString msServiceName;
366 OUString msName;
367 OUString msInternalName; // used by diagram; not displayed in UI
368 OUString msId;
369 OUString msDescription;
370 OUString msTitle;
371 bool m_isDecorative = false;
373 /* <sp> (Shape) : This element specifies the existence of a single shape.
375 Attributes:
376 - macro (Reference to Custom Function)
377 - textlink (Text Link)
378 - fLocksText (Lock Text Flag)
379 - fPublished (Publish to Server Flag)
381 <sp> element can exist as a namespace format like <xdr:sp>, <cdr:sp> etc...
384 /* specifies the custom function associated with the object.
385 "macro" attribute for <sp> element */
386 OUString msMacro;
387 /* specifies a formula linking to spreadsheet cell data.
388 "textlink" attribute for <sp> element */
389 OUString msTextLink;
390 /* indicates whether to allow text editing within this drawing object when the parent worksheet is protected.
391 "fLocksText" attribute for <sp> element */
392 bool mbFLocksText = true; // default="true"
393 /* indicates whether the shape shall be published with the worksheet when sent to the server.
394 "fPublished" attribute for <sp> element */
395 bool mbFPublished = false;
397 sal_Int32 mnSubType; // if this type is not zero, then the shape is a placeholder
398 std::optional< sal_Int32 > moSubTypeIndex;
400 ShapeStyleRefMap maShapeStyleRefs;
402 css::awt::Size maSize;
403 css::awt::Point maPosition;
404 ::std::vector<OUString> maExtDrawings;
405 Color maFontRefColorForNodes;
407 FrameType meFrameType; ///< Type for graphic frame shapes.
409 private:
411 typedef std::shared_ptr< ::oox::vml::OleObjectInfo > OleObjectInfoRef;
412 typedef std::shared_ptr< ChartShapeInfo > ChartShapeInfoRef;
414 OleObjectInfoRef mxOleObjectInfo; ///< Additional data for OLE objects.
415 ChartShapeInfoRef mxChartShapeInfo; ///< Additional data for chart shapes.
417 sal_Int32 mnRotation;
418 sal_Int32 mnDiagramRotation; // rotates shape prior to sizing, does not affect text rotation
419 bool mbFlipH;
420 bool mbFlipV;
421 bool mbHidden;
422 bool mbHiddenMasterShape; // master shapes can be hidden in layout slides
423 // we need separate flag because we don't want
424 // to propagate it when applying reference shape
425 bool mbLocked;
426 bool mbWPGChild; // Is this shape a child of a WPG shape?
427 bool mbLockedCanvas; ///< Is this shape part of a locked canvas?
428 bool mbWordprocessingCanvas; ///< Is this shape part of a wordprocessing canvas?
429 bool mbWps; ///< Is this a wps shape?
430 bool mbTextBox; ///< This shape has a textbox.
431 LinkedTxbxAttr maLinkedTxbxAttr;
432 bool mbHasLinkedTxbx; // this text box has linked text box ?
434 css::uno::Sequence<css::beans::PropertyValue> maDiagramDoms;
436 /// Z-Order.
437 sal_Int32 mnZOrder = 0;
439 /// Z-Order offset.
440 sal_Int32 mnZOrderOff = 0;
442 /// Type of data node for an in-diagram shape.
443 sal_Int32 mnDataNodeType = 0;
445 /// Aspect ratio for an in-diagram shape.
446 double mfAspectRatio = 0;
448 /// Number of child shapes to be layouted vertically inside org chart in-diagram shape.
449 sal_Int32 mnVerticalShapesCount = 0;
451 // Is this a connector shape?
452 bool mbConnector = false;
454 // temporary space for DiagramHelper in preparation for collecting data
455 // Note: I tried to use a unique_ptr here, but existing constructor func does not allow that
456 AdvancedDiagramHelper* mpDiagramHelper;
458 // association-ID to identify the Diagram ModelData
459 OUString msDiagramDataModelID;
464 #endif // INCLUDED_OOX_DRAWINGML_SHAPE_HXX
466 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */