1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
27 #include <com/sun/star/awt/Point.hpp>
28 #include <com/sun/star/awt/Size.hpp>
29 #include <com/sun/star/beans/PropertyValue.hpp>
30 #include <com/sun/star/uno/Reference.hxx>
31 #include <com/sun/star/uno/Sequence.hxx>
32 #include <oox/dllapi.h>
33 #include <oox/drawingml/color.hxx>
34 #include <oox/drawingml/drawingmltypes.hxx>
35 #include <oox/helper/helper.hxx>
36 #include <oox/helper/propertymap.hxx>
37 #include <rtl/ustring.hxx>
38 #include <sal/types.h>
40 namespace basegfx
{ class B2DHomMatrix
; }
42 namespace com
{ namespace sun
{ namespace star
{
43 namespace awt
{ struct Rectangle
; }
44 namespace drawing
{ class XShape
; }
45 namespace drawing
{ class XShapes
; }
46 namespace uno
{ class Any
; }
49 namespace oox
{ namespace core
{
53 namespace oox
{ namespace vml
{
57 namespace oox
{ namespace drawingml
{
60 struct EffectProperties
;
61 struct FillProperties
;
62 struct GraphicProperties
;
63 struct LineProperties
;
64 struct Shape3DProperties
;
66 class CustomShapeProperties
;
67 typedef std::shared_ptr
< CustomShapeProperties
> CustomShapePropertiesPtr
;
69 typedef ::std::map
< OUString
, ShapePtr
> ShapeIdMap
;
74 sal_Int32 mnThemedIdx
;
75 ShapeStyleRef() : mnThemedIdx(0) {}
78 typedef ::std::map
< sal_Int32
, ShapeStyleRef
> ShapeStyleRefMap
;
80 /** Additional information for a chart embedded in a drawing shape. */
83 OUString maFragmentPath
; ///< Path to related XML stream, e.g. for charts.
84 bool const mbEmbedShapes
; ///< True = load chart shapes into chart, false = load into parent drawpage.
86 explicit ChartShapeInfo( bool bEmbedShapes
) : mbEmbedShapes( bEmbedShapes
) {}
89 /// Attributes for a linked textbox.
94 LinkedTxbxAttr(): id(0),seq(0){};
97 class OOX_DLLPUBLIC Shape
98 : public std::enable_shared_from_this
< Shape
>
102 explicit Shape( const sal_Char
* pServiceType
= nullptr, bool bDefaultHeight
= true );
103 explicit Shape( const ShapePtr
& pSourceShape
);
106 OUString
& getServiceName(){ return msServiceName
; }
107 void setServiceName( const sal_Char
* pServiceName
);
109 PropertyMap
& getShapeProperties(){ return maShapeProperties
; }
111 LineProperties
& getLineProperties() { return *mpLinePropertiesPtr
; }
112 const LineProperties
& getLineProperties() const { return *mpLinePropertiesPtr
; }
114 FillProperties
& getFillProperties() { return *mpFillPropertiesPtr
; }
115 const FillProperties
& getFillProperties() const { return *mpFillPropertiesPtr
; }
117 GraphicProperties
& getGraphicProperties() { return *mpGraphicPropertiesPtr
; }
118 const GraphicProperties
& getGraphicProperties() const { return *mpGraphicPropertiesPtr
; }
120 CustomShapePropertiesPtr
& getCustomShapeProperties(){ return mpCustomShapePropertiesPtr
; }
122 Shape3DProperties
& get3DProperties() { return *mp3DPropertiesPtr
; }
123 const Shape3DProperties
& get3DProperties() const { return *mp3DPropertiesPtr
; }
125 table::TablePropertiesPtr
const & getTableProperties();
127 EffectProperties
& getEffectProperties() const { return *mpEffectPropertiesPtr
; }
129 void setChildPosition( css::awt::Point nPosition
){ maChPosition
= nPosition
; }
130 void setChildSize( css::awt::Size aSize
){ maChSize
= aSize
; }
132 void setPosition( css::awt::Point nPosition
){ maPosition
= nPosition
; }
133 const css::awt::Point
& getPosition() const { return maPosition
; }
135 void setSize( css::awt::Size aSize
){ maSize
= aSize
; }
136 const css::awt::Size
& getSize() const { return maSize
; }
138 void setRotation( sal_Int32 nRotation
) { mnRotation
= nRotation
; }
139 sal_Int32
getRotation() const { return mnRotation
; }
140 void setDiagramRotation( sal_Int32 nRotation
) { mnDiagramRotation
= nRotation
; }
141 void setFlip( bool bFlipH
, bool bFlipV
) { mbFlipH
= bFlipH
; mbFlipV
= bFlipV
; }
142 void addChild( const ShapePtr
& rChildPtr
) { maChildren
.push_back( rChildPtr
); }
143 std::vector
< ShapePtr
>& getChildren() { return maChildren
; }
145 void setName( const OUString
& rName
) { msName
= rName
; }
146 const OUString
& getName( ) { return msName
; }
147 void setInternalName( const OUString
& rInternalName
) { msInternalName
= rInternalName
; }
148 const OUString
& getInternalName() const { return msInternalName
; }
149 void setId( const OUString
& rId
) { msId
= rId
; }
150 const OUString
& getId() { return msId
; }
151 void setDescription( const OUString
& rDescr
) { msDescription
= rDescr
; }
152 void setHidden( bool bHidden
) { mbHidden
= bHidden
; }
153 void setHiddenMasterShape( bool bHiddenMasterShape
) { mbHiddenMasterShape
= bHiddenMasterShape
; }
154 void setLocked( bool bLocked
) { mbLocked
= bLocked
; }
155 void setSubType( sal_Int32 nSubType
) { mnSubType
= nSubType
; }
156 sal_Int32
getSubType() const { return mnSubType
; }
157 void setSubTypeIndex( sal_Int32 nSubTypeIndex
) { moSubTypeIndex
= nSubTypeIndex
; }
158 const OptValue
< sal_Int32
>& getSubTypeIndex() const { return moSubTypeIndex
; }
160 // setDefaults has to be called if styles are imported (OfficeXML is not storing properties having the default value)
161 void setDefaults(bool bHeight
);
163 ::oox::vml::OleObjectInfo
& setOleObjectType();
164 ChartShapeInfo
& setChartType( bool bEmbedShapes
);
165 void setDiagramType();
168 void setTextBody(const TextBodyPtr
& pTextBody
);
169 const TextBodyPtr
& getTextBody() { return mpTextBody
;}
170 void setMasterTextListStyle( const TextListStylePtr
& pMasterTextListStyle
);
171 const TextListStylePtr
& getMasterTextListStyle() const { return mpMasterTextListStyle
; }
173 ShapeStyleRefMap
& getShapeStyleRefs() { return maShapeStyleRefs
; }
174 const ShapeStyleRefMap
& getShapeStyleRefs() const { return maShapeStyleRefs
; }
175 const ShapeStyleRef
* getShapeStyleRef( sal_Int32 nRefType
) const;
177 // addShape is creating and inserting the corresponding XShape.
179 ::oox::core::XmlFilterBase
& rFilterBase
,
181 const css::uno::Reference
< css::drawing::XShapes
>& rxShapes
,
182 const basegfx::B2DHomMatrix
& aTransformation
,
183 FillProperties
& rShapeOrParentShapeFillProps
,
184 ShapeIdMap
* pShapeMap
= nullptr,
185 bool bInGroup
= false);
187 const css::uno::Reference
< css::drawing::XShape
> &
188 getXShape() const { return mxShape
; }
190 void applyShapeReference( const Shape
& rReferencedShape
, bool bUseText
= true );
191 const ::std::vector
<OUString
>&
192 getExtDrawings() { return maExtDrawings
; }
193 void addExtDrawingRelId( const OUString
&rRelId
) { maExtDrawings
.push_back( rRelId
); }
194 // Set font color only for extdrawings.
195 void setFontRefColorForNodes(const Color
& rColor
) { maFontRefColorForNodes
= rColor
; }
196 const Color
& getFontRefColorForNodes() const { return maFontRefColorForNodes
; }
197 void setLockedCanvas(bool bLockedCanvas
);
198 bool getLockedCanvas() { return mbLockedCanvas
;}
199 void setWps(bool bWps
);
200 bool getWps() { return mbWps
;}
201 void setTextBox(bool bTextBox
);
202 const css::uno::Sequence
<css::beans::PropertyValue
> &
203 getDiagramDoms() { return maDiagramDoms
; }
204 void setDiagramDoms(const css::uno::Sequence
<css::beans::PropertyValue
>& rDiagramDoms
) { maDiagramDoms
= rDiagramDoms
; }
205 css::uno::Sequence
< css::uno::Sequence
< css::uno::Any
> >resolveRelationshipsOfTypeFromOfficeDoc(
206 core::XmlFilterBase
& rFilter
, const OUString
& sFragment
, const OUString
& sType
);
207 void setLinkedTxbxAttributes(const LinkedTxbxAttr
& rhs
){ maLinkedTxbxAttr
= rhs
; };
208 void setTxbxHasLinkedTxtBox( const bool rhs
){ mbHasLinkedTxbx
= rhs
; };
209 const LinkedTxbxAttr
& getLinkedTxbxAttributes() { return maLinkedTxbxAttr
; };
210 bool isLinkedTxbx() { return mbHasLinkedTxbx
; };
212 void setZOrder(sal_Int32 nZOrder
) { mnZOrder
= nZOrder
; }
214 sal_Int32
getZOrder() const { return mnZOrder
; }
216 void setZOrderOff(sal_Int32 nZOrderOff
) { mnZOrderOff
= nZOrderOff
; }
218 sal_Int32
getZOrderOff() const { return mnZOrderOff
; }
220 void setDataNodeType(sal_Int32 nDataNodeType
) { mnDataNodeType
= nDataNodeType
; }
222 sal_Int32
getDataNodeType() const { return mnDataNodeType
; }
224 void setAspectRatio(double fAspectRatio
) { mfAspectRatio
= fAspectRatio
; }
226 double getAspectRatio() const { return mfAspectRatio
; }
228 /// Changes reference semantics to value semantics for fill properties.
229 void cloneFillProperties();
231 void keepDiagramDrawing(::oox::core::XmlFilterBase
& rFilterBase
, const OUString
& rFragmentPath
);
237 FRAMETYPE_GENERIC
, ///< Generic shape, no special type.
238 FRAMETYPE_OLEOBJECT
, ///< OLE object embedded in a shape.
239 FRAMETYPE_CHART
, ///< Chart embedded in a shape.
240 FRAMETYPE_DIAGRAM
, ///< Complex diagram drawing shape.
241 FRAMETYPE_TABLE
///< A table embedded in a shape.
244 css::uno::Reference
< css::drawing::XShape
> const &
246 ::oox::core::XmlFilterBase
& rFilterBase
,
247 const OUString
& rServiceName
,
249 const css::uno::Reference
< css::drawing::XShapes
>& rxShapes
,
251 bool bDoNotInsertEmptyTextBody
,
252 basegfx::B2DHomMatrix
& aTransformation
,
253 FillProperties
& rShapeOrParentShapeFillProps
,
254 bool bInGroup
= false
258 ::oox::core::XmlFilterBase
& rFilterBase
,
261 const css::uno::Reference
< css::drawing::XShapes
>& rxShapes
,
262 ShapeIdMap
* pShapeMap
,
263 const basegfx::B2DHomMatrix
& aTransformation
);
265 void keepDiagramCompatibilityInfo();
266 void convertSmartArtToMetafile( ::oox::core::XmlFilterBase
const& rFilterBase
);
268 css::uno::Reference
< css::drawing::XShape
>
269 renderDiagramToGraphic( ::oox::core::XmlFilterBase
const & rFilterBase
);
271 OUString
finalizeServiceName(
272 ::oox::core::XmlFilterBase
& rFilter
,
273 const OUString
& rServiceName
,
274 const css::awt::Rectangle
& rShapeRect
);
276 virtual void finalizeXShape(
277 ::oox::core::XmlFilterBase
& rFilter
,
278 const css::uno::Reference
< css::drawing::XShapes
>& rxShapes
);
280 void putPropertyToGrabBag(
281 const OUString
& sPropertyName
, const css::uno::Any
& aPropertyValue
);
282 void putPropertyToGrabBag(
283 const css::beans::PropertyValue
& pProperty
);
284 void putPropertiesToGrabBag(
285 const css::uno::Sequence
< css::beans::PropertyValue
>& aProperties
);
287 FillProperties
getActualFillProperties(const Theme
* pTheme
, const FillProperties
* pParentShapeFillProps
) const;
288 LineProperties
getActualLineProperties(const Theme
* pTheme
) const;
289 EffectProperties
getActualEffectProperties(const Theme
* pTheme
) const;
291 std::vector
< ShapePtr
> maChildren
; // only used for group shapes
292 css::awt::Size maChSize
; // only used for group shapes
293 css::awt::Point maChPosition
; // only used for group shapes
295 TextBodyPtr mpTextBody
;
296 LinePropertiesPtr mpLinePropertiesPtr
;
297 LinePropertiesPtr mpShapeRefLinePropPtr
;
298 FillPropertiesPtr mpFillPropertiesPtr
;
299 FillPropertiesPtr mpShapeRefFillPropPtr
;
300 GraphicPropertiesPtr mpGraphicPropertiesPtr
;
301 CustomShapePropertiesPtr mpCustomShapePropertiesPtr
;
302 table::TablePropertiesPtr mpTablePropertiesPtr
;
303 Shape3DPropertiesPtr mp3DPropertiesPtr
;
304 EffectPropertiesPtr mpEffectPropertiesPtr
;
305 EffectPropertiesPtr mpShapeRefEffectPropPtr
;
306 PropertyMap maShapeProperties
;
307 PropertyMap maDefaultShapeProperties
;
308 TextListStylePtr mpMasterTextListStyle
;
309 css::uno::Reference
< css::drawing::XShape
> mxShape
;
311 OUString msServiceName
;
313 OUString msInternalName
; // used by diagram; not displayed in UI
315 OUString msDescription
;
316 sal_Int32 mnSubType
; // if this type is not zero, then the shape is a placeholder
317 OptValue
< sal_Int32
> moSubTypeIndex
;
319 ShapeStyleRefMap maShapeStyleRefs
;
321 css::awt::Size maSize
;
322 css::awt::Point maPosition
;
323 ::std::vector
<OUString
> maExtDrawings
;
324 Color maFontRefColorForNodes
;
326 FrameType meFrameType
; ///< Type for graphic frame shapes.
330 typedef std::shared_ptr
< ::oox::vml::OleObjectInfo
> OleObjectInfoRef
;
331 typedef std::shared_ptr
< ChartShapeInfo
> ChartShapeInfoRef
;
333 OleObjectInfoRef mxOleObjectInfo
; ///< Additional data for OLE objects.
334 ChartShapeInfoRef mxChartShapeInfo
; ///< Additional data for chart shapes.
336 sal_Int32 mnRotation
;
337 sal_Int32 mnDiagramRotation
; // rotates shape prior to sizing, does not affect text rotation
341 bool mbHiddenMasterShape
; // master shapes can be hidden in layout slides
342 // we need separate flag because we don't want
343 // to propagate it when applying reference shape
345 bool mbLockedCanvas
; ///< Is this shape part of a locked canvas?
346 bool mbWps
; ///< Is this a wps shape?
347 bool mbTextBox
; ///< This shape has a textbox.
348 LinkedTxbxAttr maLinkedTxbxAttr
;
349 bool mbHasLinkedTxbx
; // this text box has linked text box ?
351 css::uno::Sequence
<css::beans::PropertyValue
> maDiagramDoms
;
354 sal_Int32 mnZOrder
= 0;
357 sal_Int32 mnZOrderOff
= 0;
359 /// Type of data node for an in-diagram shape.
360 sal_Int32 mnDataNodeType
= 0;
362 /// Aspect ratio for an in-diagram shape.
363 double mfAspectRatio
= 0;
368 #endif // INCLUDED_OOX_DRAWINGML_SHAPE_HXX
370 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */