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 .
22 #include <svx/svdobj.hxx>
23 #include <svx/svdotext.hxx>
24 #include <svx/svdhdl.hxx>
26 #include <com/sun/star/uno/Reference.h>
27 #include <com/sun/star/drawing/XCustomShapeEngine.hpp>
28 #include <com/sun/star/drawing/EnhancedCustomShapeAdjustmentValue.hpp>
29 #include <svx/svxdllapi.h>
30 #include <o3tl/typed_flags_set.hxx>
36 class CustomShapeProperties
;
40 class SdrAShapeObjGeoData final
: public SdrTextObjGeoData
45 double fObjectRotation
;
47 css::uno::Sequence
< css::drawing::EnhancedCustomShapeAdjustmentValue
> aAdjustmentSeq
;
50 enum class CustomShapeHandleModes
55 RESIZE_ABSOLUTE_X
= 4,
56 RESIZE_ABSOLUTE_Y
= 8,
59 RESIZE_ABSOLUTE_NEGX
= 64
64 template<> struct typed_flags
<CustomShapeHandleModes
> : is_typed_flags
<CustomShapeHandleModes
, 127> {};
67 struct SdrCustomShapeInteraction
69 css::uno::Reference
< css::drawing::XCustomShapeHandle
> xInteraction
;
70 css::awt::Point aPosition
;
71 CustomShapeHandleModes nMode
;
74 class SVXCORE_DLLPUBLIC SdrObjCustomShape
: public SdrTextObj
77 // fObjectRotation is containing the object rotation in degrees.
78 double m_fObjectRotation
;
79 bool mbAdjustingTextFrameWidthAndHeight
;
82 virtual std::unique_ptr
<sdr::contact::ViewContact
> CreateObjectSpecificViewContact() override
;
83 virtual void setUnoShape(const css::uno::Reference
<css::drawing::XShape
>& rxUnoShape
) override
;
86 virtual std::unique_ptr
<sdr::properties::BaseProperties
> CreateObjectSpecificProperties() override
;
88 // to allow sdr::properties::CustomShapeProperties access
89 friend class sdr::properties::CustomShapeProperties
;
91 css::uno::Reference
< css::drawing::XShape
> mXRenderedCustomShape
;
93 mutable css::uno::Reference
< css::drawing::XCustomShapeEngine
> mxCustomShapeEngine
;
95 // #i37011# render geometry shadow
96 rtl::Reference
<SdrObject
> mpLastShadowGeometry
;
98 css::uno::Reference
< css::drawing::XCustomShapeEngine
> const & GetCustomShapeEngine() const;
100 std::vector
< SdrCustomShapeInteraction
> GetInteractionHandles() const; // needed in unit test
101 SVX_DLLPRIVATE
void DragCreateObject( SdrDragStat
& rDrag
);
102 SVX_DLLPRIVATE
void DragResizeCustomShape( const tools::Rectangle
& rNewRect
);
103 void DragMoveCustomShapeHdl( const Point
& rDestination
,
104 const sal_uInt16 nCustomShapeHdlNum
, bool bMoveCalloutRectangle
); // needed in unit test
106 // #i37011# centralize throw-away of render geometry
107 void InvalidateRenderGeometry();
110 void ImpCheckCustomGluePointsAreAdded();
112 // returns the new text rect that corresponds to the current logic rect, the return value can be empty if nothing changed.
113 tools::Rectangle
ImpCalculateTextFrame( const bool bHgt
, const bool bWdt
);
117 const SdrObject
* GetSdrObjectFromCustomShape() const;
118 const SdrObject
* GetSdrObjectShadowFromCustomShape() const;
119 bool GetTextBounds( tools::Rectangle
& rTextBound
) const;
120 virtual bool IsTextPath() const override
;
121 basegfx::B2DPolyPolygon
GetLineGeometry( const bool bBezierAllowed
) const;
124 // #115391# new method for SdrObjCustomShape and SdrTextObj to correctly handle and set
125 // SdrTextMinFrameWidthItem and SdrTextMinFrameHeightItem based on all settings, necessities
127 virtual void AdaptTextMinSize() override
;
129 Size m_aSuggestedTextFrameSize
;
131 virtual void InternalSetStyleSheet( SfxStyleSheet
* pNewStyleSheet
, bool bDontRemoveHardAttr
, bool bBroadcast
, bool bAdjustTextFrameWidthAndHeight
= true ) override
;
134 bool UseNoFillStyle() const;
136 bool IsMirroredX() const;
137 bool IsMirroredY() const;
138 void SetMirroredX( const bool bMirroredX
);
139 void SetMirroredY( const bool bMirroredY
);
141 double GetObjectRotation() const { return m_fObjectRotation
;}
142 double GetExtraTextRotation( const bool bPreRotation
= false ) const;
144 SdrObjCustomShape(SdrModel
& rSdrModel
);
145 SdrObjCustomShape(SdrModel
& rSdrModel
, SdrObjCustomShape
const & rSource
);
146 virtual ~SdrObjCustomShape() override
;
148 /* is merging default attributes from type-shape into the SdrCustomShapeGeometryItem. If pType
149 is NULL then the type is being taken from the "Type" property of the SdrCustomShapeGeometryItem.
150 MergeDefaultAttributes is called when creating CustomShapes via UI and after importing */
151 void MergeDefaultAttributes( const OUString
* pType
= nullptr );
153 /* the method is checking if the geometry data is unchanged/default, in this case the data might not be stored */
154 enum class DefaultType
165 bool IsDefaultGeometry( const DefaultType eDefaultType
) const;
167 virtual SdrObjKind
GetObjIdentifier() const override
;
168 virtual void TakeObjInfo(SdrObjTransformInfoRec
& rInfo
) const override
;
170 virtual void Move(const Size
& rSiz
) override
;
171 virtual void Shear(const Point
& rRef
, Degree100 nAngle
, double tn
, bool bVShear
) override
;
172 virtual void SetSnapRect(const tools::Rectangle
& rRect
) override
;
173 virtual void SetLogicRect(const tools::Rectangle
& rRect
) override
;
174 virtual void AdjustToMaxRect( const tools::Rectangle
& rMaxRect
, bool bShrinkOnly
= false ) override
;
176 virtual void NbcMove(const Size
& rSiz
) override
;
177 virtual void NbcResize(const Point
& rRef
, const Fraction
& xFact
, const Fraction
& yFact
) override
;
178 virtual void NbcRotate(const Point
& rRef
, Degree100 nAngle
, double sn
, double cs
) override
;
179 virtual void NbcMirror(const Point
& rRef1
, const Point
& rRef2
) override
;
180 virtual void NbcShear(const Point
& rRef
, Degree100 nAngle
, double tn
, bool bVShear
) override
;
181 virtual void NbcSetSnapRect(const tools::Rectangle
& rRect
) override
;
182 virtual void NbcSetLogicRect(const tools::Rectangle
& rRect
, bool bAdaptTextMinSize
= true) override
;
184 virtual SdrGluePoint
GetVertexGluePoint(sal_uInt16 nNum
) const override
;
186 // special drag methods
187 virtual bool hasSpecialDrag() const override
;
188 virtual bool beginSpecialDrag(SdrDragStat
& rDrag
) const override
;
189 virtual bool applySpecialDrag(SdrDragStat
& rDrag
) override
;
191 virtual bool MovCreate(SdrDragStat
& rStat
) override
; // #i37448#
192 virtual bool EndCreate(SdrDragStat
& rStat
, SdrCreateCmd eCmd
) override
;
195 * Allows suggesting the text frame size: in case the application has its
196 * own text associated to the shape, instead of using the shape's editeng
199 void SuggestTextFrameSize(Size aSuggestedTextFrameSize
);
200 virtual bool AdjustTextFrameWidthAndHeight(tools::Rectangle
& rR
, bool bHgt
= true, bool bWdt
= true) const override
;
201 virtual bool NbcAdjustTextFrameWidthAndHeight(bool bHgt
= true, bool bWdt
= true) override
;
202 virtual bool AdjustTextFrameWidthAndHeight() override
;
203 virtual bool IsAutoGrowHeight() const override
;
204 virtual bool IsAutoGrowWidth() const override
;
205 virtual void SetVerticalWriting(bool bVertical
) override
;
206 virtual void TakeTextEditArea(Size
* pPaperMin
, Size
* pPaperMax
, tools::Rectangle
* pViewInit
, tools::Rectangle
* pViewMin
) const override
;
207 virtual void EndTextEdit( SdrOutliner
& rOutl
) override
;
208 virtual void TakeTextAnchorRect( tools::Rectangle
& rAnchorRect
) const override
;
209 virtual void TakeTextRect( SdrOutliner
& rOutliner
, tools::Rectangle
& rTextRect
, bool bNoEditText
,
210 tools::Rectangle
* pAnchorRect
, bool bLineWidth
= true ) const override
;
211 virtual rtl::Reference
<SdrObject
> CloneSdrObject(SdrModel
& rTargetModel
) const override
;
213 virtual OUString
TakeObjNameSingul() const override
;
214 virtual OUString
TakeObjNamePlural() const override
;
216 virtual basegfx::B2DPolyPolygon
TakeCreatePoly( const SdrDragStat
& rDrag
) const override
;
218 virtual basegfx::B2DPolyPolygon
TakeXorPoly() const override
;
219 virtual basegfx::B2DPolyPolygon
TakeContour() const override
;
221 virtual void NbcSetOutlinerParaObject(std::optional
<OutlinerParaObject
> pTextObject
, bool bAdjustTextFrameWidthAndHeight
= true) override
;
223 virtual rtl::Reference
<SdrObject
> DoConvertToPolyObj(bool bBezier
, bool bAddText
) const override
;
225 // react on model/page change
226 virtual void handlePageChange(SdrPage
* pOldPage
, SdrPage
* pNewPage
) override
;
228 virtual std::unique_ptr
<SdrObjGeoData
> NewGeoData() const override
;
229 virtual void SaveGeoData(SdrObjGeoData
&rGeo
) const override
;
230 virtual void RestoreGeoData(const SdrObjGeoData
&rGeo
) override
;
232 // need to take fObjectRotation instead of aGeo.nAngle, replace it temporary
233 virtual bool TRGetBaseGeometry(basegfx::B2DHomMatrix
& rMatrix
, basegfx::B2DPolyPolygon
& rPolyPolygon
) const override
;
234 virtual void TRSetBaseGeometry(const basegfx::B2DHomMatrix
& rMatrix
, const basegfx::B2DPolyPolygon
& rPolyPolygon
) override
;
236 virtual const SdrGluePointList
* GetGluePointList() const override
;
237 //virtual SdrGluePointList* GetGluePointList();
238 virtual SdrGluePointList
* ForceGluePointList() override
;
240 virtual sal_uInt32
GetHdlCount() const override
;
241 virtual void AddToHdlList(SdrHdlList
& rHdlList
) const override
;
244 static bool doConstructOrthogonal(std::u16string_view rName
);
246 using SdrTextObj::NbcSetOutlinerParaObject
;
248 OUString
GetCustomShapeName() const;
251 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */