Coverage Report

Created: 2026-06-30 11:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/svx/svdedtv.hxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
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/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
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 .
18
 */
19
20
#ifndef INCLUDED_SVX_SVDEDTV_HXX
21
#define INCLUDED_SVX_SVDEDTV_HXX
22
23
#include <svx/svdmrkv.hxx>
24
#include <svx/xpoly.hxx>
25
#include <svx/svdmodel.hxx>
26
#include <svx/svxdllapi.h>
27
#include <svx/svdundo.hxx>
28
#include <o3tl/typed_flags_set.hxx>
29
30
class SfxStyleSheet;
31
class SvdProgressInfo;
32
33
enum class SdrHorAlign  {
34
    NONE,
35
    Left,
36
    Right,
37
    Center
38
};
39
40
enum class SdrVertAlign {
41
    NONE,
42
    Top,
43
    Bottom,
44
    Center
45
};
46
47
enum class SdrMergeMode {
48
    Merge,
49
    Subtract,
50
    Intersect
51
};
52
53
// Options for InsertObject()
54
enum class SdrInsertFlags
55
{
56
    NONE        = 0x0000,
57
    DONTMARK    = 0x0001, /* object will not be marked (the actual marking remains) */
58
    ADDMARK     = 0x0002, /* object will be added an existing selection  */
59
    SETDEFATTR  = 0x0004, /* actual attributes (+StyleSheet) are assigned to the object */
60
    SETDEFLAYER = 0x0008, /* actual layer is assigned to the object */
61
};
62
namespace o3tl
63
{
64
    template<> struct typed_flags<SdrInsertFlags> : is_typed_flags<SdrInsertFlags, 0x0f> {};
65
}
66
67
class SVXCORE_DLLPUBLIC SdrEditView : public SdrMarkView
68
{
69
    friend class SdrPageView;
70
    friend class SdrDragDistort;
71
    friend class SdrDragCrook;
72
73
protected:
74
75
    // cache the transformation queries, etc. a little
76
    bool m_bPossibilitiesDirty : 1;
77
    bool m_bReadOnly : 1;
78
    bool m_bGroupPossible : 1;
79
    bool m_bUnGroupPossible : 1;
80
    bool m_bGrpEnterPossible : 1;
81
    bool m_bToTopPossible : 1;
82
    bool m_bToBtmPossible : 1;
83
    bool m_bReverseOrderPossible : 1;
84
    bool m_bImportMtfPossible : 1;
85
    bool m_bCombinePossible : 1;
86
    bool m_bDismantlePossible : 1;
87
    bool m_bCombineNoPolyPolyPossible : 1;
88
    bool m_bDismantleMakeLinesPossible : 1;
89
    bool m_bOrthoDesiredOnMarked : 1;
90
    bool m_bOneOrMoreMovable : 1;        // at least one object is moveable
91
    bool m_bMoreThanOneNoMovRot : 1;     // more than one object is not movable nor turnable (Crook)
92
    bool m_bContortionPossible : 1;      // all polygones (grouped if necessary)
93
    bool m_bMoveAllowed : 1;
94
    bool m_bResizeFreeAllowed : 1;
95
    bool m_bResizePropAllowed : 1;
96
    bool m_bRotateFreeAllowed : 1;
97
    bool m_bRotate90Allowed : 1;
98
    bool m_bMirrorFreeAllowed : 1;
99
    bool m_bMirror45Allowed : 1;
100
    bool m_bMirror90Allowed : 1;
101
    bool m_bShearAllowed : 1;
102
    bool m_bEdgeRadiusAllowed : 1;
103
    bool m_bTransparenceAllowed : 1;
104
    bool m_bCropAllowed : 1;
105
    bool m_bGradientAllowed : 1;
106
    bool m_bCanConvToPath : 1;
107
    bool m_bCanConvToPoly : 1;
108
    bool m_bCanConvToContour : 1;
109
    bool m_bMoveProtect : 1;
110
    bool m_bResizeProtect : 1;
111
112
private:
113
    SVX_DLLPRIVATE void ImpResetPossibilityFlags();
114
115
protected:
116
    SAL_DLLPRIVATE void ImpBroadcastEdgesOfMarkedNodes();
117
118
    // convert the objects marked in poly resp. bezier
119
    SAL_DLLPRIVATE void ImpConvertTo(bool bPath, bool bLineToArea);
120
121
    // converts an object, when positive it removes the old one from its List
122
    // and inserts the new one instead. including Undo.
123
    // Nor MarkEntry nor ModelChgBroadcast is created.
124
    SAL_DLLPRIVATE rtl::Reference<SdrObject> ImpConvertOneObj(SdrObject* pObj, bool bPath, bool bLineToArea);
125
126
    // set both flags: bToTopPossible and bToBtmPossible.
127
    // bToTopPossibleDirty and bToBtmPossibleDirty are reset at the same time
128
    SAL_DLLPRIVATE void ImpCheckToTopBtmPossible();
129
130
    // for CombineMarkedObjects and DismantleMarkedObjects
131
    SAL_DLLPRIVATE void ImpCopyAttributes(const SdrObject* pSource, SdrObject* pDest) const;
132
133
    // for CombineMarkedObjects
134
    SAL_DLLPRIVATE static bool ImpCanConvertForCombine1(const SdrObject* pObj);
135
    SAL_DLLPRIVATE static bool ImpCanConvertForCombine(const SdrObject* pObj);
136
    SAL_DLLPRIVATE static basegfx::B2DPolyPolygon ImpGetPolyPolygon1(const SdrObject* pObj);
137
    SAL_DLLPRIVATE static basegfx::B2DPolyPolygon ImpGetPolyPolygon(const SdrObject* pObj);
138
    SAL_DLLPRIVATE static basegfx::B2DPolygon ImpCombineToSinglePolygon(const basegfx::B2DPolyPolygon& rPolyPolygon);
139
140
    // for DismantleMarkedObjects
141
    SAL_DLLPRIVATE static bool ImpCanDismantle(const basegfx::B2DPolyPolygon& rPpolyPpolygon, bool bMakeLines);
142
    SAL_DLLPRIVATE static bool ImpCanDismantle(const SdrObject* pObj, bool bMakeLines);
143
    SAL_DLLPRIVATE void ImpDismantleOneObject(const SdrObject* pObj, SdrObjList& rOL, size_t& rPos, SdrPageView* pPV, bool bMakeLines);
144
    SAL_DLLPRIVATE static void ImpCrookObj(SdrObject* pO, const Point& rRef, const Point& rRad, SdrCrookMode eMode,
145
        bool bVertical, bool bNoContortion, bool bRotate, const tools::Rectangle& rMarkRect);
146
    SAL_DLLPRIVATE static void ImpDistortObj(SdrObject* pO, const tools::Rectangle& rRef, const XPolygon& rDistortedRect, bool bNoContortion);
147
    SAL_DLLPRIVATE bool ImpDelLayerCheck(SdrObjList const * pOL, SdrLayerID nDelID) const;
148
    SAL_DLLPRIVATE void ImpDelLayerDelObjs(SdrObjList* pOL, SdrLayerID nDelID);
149
150
    // Removes all objects of the MarkList from their ObjLists including Undo.
151
    // The entries in rMark remain.
152
    // @return a list of objects that must be deleted after the outermost EndUndo
153
    SAL_DLLPRIVATE std::vector<rtl::Reference<SdrObject>> DeleteMarkedList(SdrMarkList const& rMark); // DeleteMarked -> DeleteMarkedList
154
155
    // Check possibilities of all marked objects
156
    virtual void CheckPossibilities();
157
0
    void ForcePossibilities() const { if (m_bPossibilitiesDirty || mbSomeObjChgdFlag) const_cast<SdrEditView*>(this)->CheckPossibilities(); }
158
159
protected:
160
    // #i71538# make constructors of SdrView sub-components protected to avoid incomplete incarnations which may get casted to SdrView
161
    SAL_DLLPRIVATE SdrEditView(
162
        SdrModel& rSdrModel,
163
        OutputDevice* pOut);
164
165
    SAL_DLLPRIVATE virtual ~SdrEditView() override;
166
167
public:
168
    // each call of an undo-capable method from its view, generates an undo action.
169
    // If one wishes to group method calls into one, these calls should be put
170
    // between BegUndo() and EndUndo() calls (unlimited).
171
    // The comment used for the UndoAction is the first BegUndo(String).
172
    // In this case NotifyNewUndoAction is called at the last EndUndo().
173
    // NotifyNewUndoAction() is not called for an empty group
174
    void BegUndo()
175
0
    {
176
        // open undo-grouping
177
0
        GetModel().BegUndo();
178
0
    }
179
    void BegUndo(const OUString& rComment)
180
0
    {
181
        // open undo-grouping
182
0
        GetModel().BegUndo(rComment);
183
0
    }
184
    void BegUndo(const OUString& rComment, const OUString& rObjDescr, SdrRepeatFunc eFunc=SdrRepeatFunc::NONE)
185
0
    {
186
        // open undo-grouping
187
0
        GetModel().BegUndo(rComment,rObjDescr,eFunc);
188
0
    }
189
190
    void EndUndo(); // close undo-grouping  (incl. BroadcastEdges)
191
192
    void AddUndo(std::unique_ptr<SdrUndoAction> pUndo)
193
0
    {
194
        // add action
195
0
        GetModel().AddUndo(std::move(pUndo));
196
0
    }
197
198
    // only after first BegUndo or before last EndUndo:
199
    void SetUndoComment(const OUString& rComment, const OUString& rObjDescr)
200
0
    {
201
0
        GetModel().SetUndoComment(rComment,rObjDescr);
202
0
    }
203
204
    bool IsUndoEnabled() const;
205
206
    /**
207
     * Checks if this or other views have an active text edit, if true, end them.
208
     */
209
    void EndTextEditAllViews() const;
210
    void EndTextEditCurrentView(bool bDontDeleteReally = false);
211
212
    SAL_DLLPRIVATE std::vector< std::unique_ptr<SdrUndoAction> > CreateConnectorUndo( const SdrObject& rO );
213
    SAL_DLLPRIVATE void AddUndoActions( std::vector< std::unique_ptr<SdrUndoAction> > );
214
215
    // Layermanagement with Undo.
216
    void InsertNewLayer(const OUString& rName, sal_uInt16 nPos);
217
    // Delete a layer including all objects contained
218
    void DeleteLayer(const OUString& rName);
219
220
    // Marked objects which are outside a page
221
    // are assigned to another page; at the moment without undo!!!
222
    void ForceMarkedObjToAnotherPage();
223
0
    void ForceMarkedToAnotherPage()   { ForceMarkedObjToAnotherPage(); }
224
225
    // delete all marked objects
226
    void DeleteMarkedObj();
227
228
    // Set a logical enclosing rectangle for all marked objects.
229
    // It is not guaranteed if this succeeds, as a horizontal
230
    // line has always a height of 0
231
    void SetMarkedObjRect(const tools::Rectangle& rRect);
232
    void MoveMarkedObj(const Size& rSiz, bool bCopy=false);
233
    void ResizeMarkedObj(const Point& rRef, double xFact, double yFact, bool bCopy=false);
234
    bool IsMarkedObjSizeValid(const Size& aTargetSize);
235
    SAL_DLLPRIVATE void ResizeMultMarkedObj(const Point& rRef, double xFact, double yFact, const bool bWdh, const bool bHgt);
236
    SAL_DLLPRIVATE Degree100 GetMarkedObjRotate() const;
237
    void RotateMarkedObj(const Point& rRef, Degree100 nAngle, bool bCopy=false);
238
    SAL_DLLPRIVATE void MirrorMarkedObj(const Point& rRef1, const Point& rRef2, bool bCopy=false);
239
    void MirrorMarkedObjHorizontal();
240
    void MirrorMarkedObjVertical();
241
    SAL_DLLPRIVATE Degree100 GetMarkedObjShear() const;
242
    SAL_DLLPRIVATE void ShearMarkedObj(const Point& rRef, Degree100 nAngle, bool bVShear=false, bool bCopy=false);
243
    SAL_DLLPRIVATE void CrookMarkedObj(const Point& rRef, const Point& rRad, SdrCrookMode eMode, bool bVertical, bool bNoContortion, bool bCopy=false);
244
    SAL_DLLPRIVATE void DistortMarkedObj(const tools::Rectangle& rRef, const XPolygon& rDistortedRect, bool bNoContortion, bool bCopy=false);
245
246
    // copy marked objects and mark them instead of the old ones
247
    void CopyMarkedObj();
248
0
    void SetAllMarkedRect(const tools::Rectangle& rRect) { SetMarkedObjRect(rRect); }
249
0
    void MoveAllMarked(const Size& rSiz, bool bCopy=false) { MoveMarkedObj(rSiz,bCopy); }
250
0
    void ResizeAllMarked(const Point& rRef, double xFact, double yFact) { ResizeMarkedObj(rRef,xFact,yFact); }
251
0
    void RotateAllMarked(const Point& rRef, Degree100 nAngle) { RotateMarkedObj(rRef,nAngle); }
252
0
    void MirrorAllMarkedHorizontal() { MirrorMarkedObjHorizontal(); }
253
0
    void MirrorAllMarkedVertical() { MirrorMarkedObjVertical(); }
254
0
    void CopyMarked() { CopyMarkedObj(); }
255
0
    bool IsMoveAllowed() const { ForcePossibilities(); return m_bMoveAllowed && !m_bMoveProtect; }
256
    bool IsResizeAllowed(bool bProp=false) const;
257
    bool IsRotateAllowed(bool b90Deg=false) const;
258
    bool IsMirrorAllowed(bool b45Deg=false, bool b90Deg=false) const;
259
    bool IsTransparenceAllowed() const;
260
    bool IsGradientAllowed() const;
261
    bool IsShearAllowed() const;
262
    bool IsEdgeRadiusAllowed() const;
263
    bool IsCrookAllowed(bool bNoContortion=false) const;
264
    SAL_DLLPRIVATE bool IsCropAllowed() const;
265
    bool IsDistortAllowed(bool bNoContortion=false) const;
266
267
    // Consolidate the text from multiple, selected TextObjects,
268
    // attempting to identify paragraph fragments and join them together
269
    void CombineMarkedTextObjects();
270
271
    // Unite several objects to a polygon:
272
    // - rectangles/circles/text... are implicitly converted.
273
    // - polygones are closed automatically
274
    // - attributes and layer are taken from the first object marked
275
    //   (thus from lowest Z-order).
276
    // - group objects are included when all (!) member objects of
277
    //   the group can be changed. If a group includes for example
278
    //   a bitmap or an OLE-object, the complete group is not considered.
279
    // bNoPolyPoly=TRUE: all is grouped to one single polygon
280
    void CombineMarkedObjects(bool bNoPolyPoly = true);
281
282
    // for combining multiple polygons, with direct support of the modes
283
    // SID_POLY_MERGE, SID_POLY_SUBSTRACT, SID_POLY_INTERSECT
284
    void MergeMarkedObjects(SdrMergeMode eMode);
285
286
    // for distribution dialog function
287
    void DistributeMarkedObjects(sal_uInt16 SlotID);
288
289
    // for setting either the width or height of all selected
290
    // objects to the width/height of the last selected object
291
    // of the selection
292
    void EqualizeMarkedObjects(bool bWidth);
293
294
    // Decompose marked polypolygon objects into polygons.
295
    // Grouped objects are searched and decomposed, if all member objects are PathObjs.
296
    // bMakeLines=TRUE:  all polygones are decomposed into single lines resp. bezier segments
297
    void DismantleMarkedObjects(bool bMakeLines=false);
298
    bool IsCombinePossible(bool bNoPolyPoly=false) const;
299
    bool IsDismantlePossible(bool bMakeLines=false) const;
300
301
    // Inserts a new, completely constructed object. Subsequently the object belongs to
302
    // the model. After insertion the object is marked (if not prevented by nOptions).
303
    // Sometimes the object is not inserted, but deleted, this is the case when
304
    // the target layer is locked or not visible. In this case
305
    // the method returns FALSE.
306
    // Amongst others the method does not create an undo-action.
307
    bool InsertObjectAtView(SdrObject* pObj, SdrPageView& rPV, SdrInsertFlags nOptions=SdrInsertFlags::NONE);
308
309
    // Replace one drawing object by another.
310
    // *pNewObj belongs to me, *pOldObj is changed into Undo.
311
    // In any case an undo grouping is required and should be applied, e.g.:
312
    // aStr+=" replace";
313
    // BegUndo(aStr);
314
    // ReplaceObject(...);
315
316
    // EndUndo();
317
    void ReplaceObjectAtView(SdrObject* pOldObj, SdrPageView& rPV, SdrObject* pNewObj, bool bMark=true);
318
319
    SAL_DLLPRIVATE void SetNotPersistAttrToMarked(const SfxItemSet& rAttr);
320
    SAL_DLLPRIVATE void MergeNotPersistAttrFromMarked(SfxItemSet& rAttr) const;
321
    void MergeAttrFromMarked(SfxItemSet& rAttr, bool bOnlyHardAttr) const;
322
    SfxItemSet GetAttrFromMarked(bool bOnlyHardAttr) const;
323
    void SetAttrToMarked(const SfxItemSet& rAttr, bool bReplaceAll);
324
325
    // geometrical attribute (position, size, rotation angle)
326
    // A PageOrigin set at a position is taken into account.
327
    SfxItemSet GetGeoAttrFromMarked() const;
328
    // In LOK, interactive shape movement uses this function
329
    // in that case, margin is not taken into account
330
    // and the final position of the shape becomes incorrect
331
    // However, "Position and Size" dialog and other cases already add the margins.
332
    void SetGeoAttrToMarked(const SfxItemSet& rAttr, bool addPageMargin = false);
333
334
    // Returns NULL if:
335
    // - nothing is marked,
336
    // - no stylesheet is set at the marked object
337
    // - point the marked objects to different StyleSheets for multiple selections
338
    SfxStyleSheet* GetStyleSheetFromMarked() const;
339
340
    // at the moment without undo :(
341
    SAL_DLLPRIVATE void SetStyleSheetToMarked(SfxStyleSheet* pStyleSheet, bool bDontRemoveHardAttr);
342
343
    /* new interface src537 */
344
    SAL_DLLPRIVATE void GetAttributes(SfxItemSet& rTargetSet, bool bOnlyHardAttr) const;
345
346
    SAL_DLLPRIVATE void SetAttributes(const SfxItemSet& rSet, bool bReplaceAll);
347
    SAL_DLLPRIVATE SfxStyleSheet* GetStyleSheet() const; // SfxStyleSheet* GetStyleSheet(bool& rOk) const;
348
    SAL_DLLPRIVATE void SetStyleSheet(SfxStyleSheet* pStyleSheet, bool bDontRemoveHardAttr);
349
350
    // Group all marked objects to a single group.
351
    // Subsequently mark the new group . If the group spawns multiple
352
    // pages a group is created per page.
353
    // All groups created are subsequently marked.
354
    // The method creates SdrObjGroup-instances.
355
    void GroupMarked();
356
357
    // All marked object groups are dissolved (1 level).
358
    // Now all previously marked member objects are marked.
359
    // Previously marked objects, which are not group objects, remain marked.
360
    void UnGroupMarked();
361
362
0
    bool IsGroupPossible() const { ForcePossibilities(); return m_bGroupPossible; }
363
0
    bool IsUnGroupPossible() const { ForcePossibilities(); return m_bUnGroupPossible; }
364
0
    bool IsGroupEnterPossible() const { ForcePossibilities(); return m_bGrpEnterPossible; }
365
366
    // Convert marked objects to polygones/Beziercurves. The bool-functions
367
    // return sal_True, if at least one marked object could be converted.
368
    // Also member objects of group objects are converted.
369
    // For a better description see: SdrObj.HXX
370
0
    bool IsConvertToPathObjPossible() const { ForcePossibilities(); return m_bCanConvToPath; }
371
0
    bool IsConvertToPolyObjPossible() const { ForcePossibilities(); return m_bCanConvToPoly; }
372
0
    bool IsConvertToContourPossible() const { ForcePossibilities(); return m_bCanConvToContour; }
373
    void ConvertMarkedToPathObj(bool bLineToArea);
374
    SAL_DLLPRIVATE void ConvertMarkedToPolyObj();
375
376
    // Align all marked objects vertically. Normally the SnapRect of an object is used.
377
    void AlignMarkedObjects(SdrHorAlign eHor, SdrVertAlign eVert);
378
    bool IsAlignPossible() const;
379
380
    // move marked objects "up"
381
    void MovMarkedToTop();
382
383
    // move marked objects "down"
384
    void MovMarkedToBtm();
385
386
    // move marked objects "at top"
387
    void PutMarkedToTop();
388
389
    // move marked objects "at bottom"
390
    void PutMarkedToBtm();
391
392
    // move marked immediately before the object passed
393
    // NULL -> as PutMarkedToTop();
394
    void PutMarkedInFrontOfObj(const SdrObject* pRefObj);
395
396
    // move marked immediately after object passed
397
    // NULL -> as PutMarkedToBtm();
398
    void PutMarkedBehindObj(const SdrObject* pRefObj);
399
400
    // swap Z-Order of marked objects
401
    void ReverseOrderOfMarked();
402
403
    // Check if forward, backward is possible.
404
    // GetMaxToBtmObj() is only partly taken into account by these methods.
405
    // Which means it can happen that IsToTopPossible() returns sal_True,
406
    // but MovMarkedToTop() changes nothing (e.g. for multiple selections),
407
    // as restriction derived via a view by GetMaxToTopObj() prevents this.
408
0
    bool IsToTopPossible() const { ForcePossibilities(); return m_bToTopPossible; }
409
0
    bool IsToBtmPossible() const { ForcePossibilities(); return m_bToBtmPossible; }
410
0
    bool IsReverseOrderPossible() const { ForcePossibilities(); return m_bReverseOrderPossible; }
411
412
    // Using this method the view determines how far an object
413
    // can be moved forward or backward (Z-order).
414
    // The object returned is not "obsolete". When NULL is
415
    // returned there is not such a restriction.
416
    virtual SdrObject* GetMaxToTopObj(SdrObject* pObj) const;
417
    virtual SdrObject* GetMaxToBtmObj(SdrObject* pObj) const;
418
419
    // Next method is called, if via ToTop, ToBtm, ... the
420
    // sequence of object has been changed. It is called after
421
    // each SdrObjList::SetObjectOrdNum(nOldPos,nNewPos);
422
    virtual void ObjOrderChanged(SdrObject* pObj, size_t nOldPos, size_t nNewPos);
423
424
    // If one or more objects of the type SdrGrafObj or SdrOle2Obj
425
    // are marked and these are capable to deliver a StarView-metafile,
426
    // this methods converts the metafile to a drawing object.
427
    // The SdrGrafObjs/SdrOle2Objs are replaced by the new objects.
428
    void DoImportMarkedMtf(SvdProgressInfo *pProgrInfo=nullptr);
429
0
    bool IsImportMtfPossible() const { ForcePossibilities(); return m_bImportMtfPossible; }
430
431
    // override SdrMarkView, for internal use
432
    SAL_DLLPRIVATE virtual void MarkListHasChanged() override;
433
    SAL_DLLPRIVATE virtual void ModelHasChanged() override;
434
};
435
436
#endif // INCLUDED_SVX_SVDEDTV_HXX
437
438
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */