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 <cppuhelper/weak.hxx>
23 #include <svl/stylesheetuser.hxx>
24 #include <vcl/prntypes.hxx>
25 #include <svl/itemset.hxx>
26 #include <svx/sdrpageuser.hxx>
27 #include <svx/sdr/contact/viewobjectcontactredirector.hxx>
28 #include <svx/sdrmasterpagedescriptor.hxx>
29 #include <svx/svxdllapi.h>
30 #include <com/sun/star/container/XIndexAccess.hpp>
31 #include <com/sun/star/drawing/XDrawPage.hpp>
32 #include <svx/svdobj.hxx>
33 #include <unotools/weakref.hxx>
41 namespace model
{ class Theme
; }
42 namespace reportdesign
{ class OSection
; }
43 namespace sdr::contact
{ class ViewContact
; }
52 class SvxUnoDrawPagesAccess
;
54 ////////////////////////////////////////////////////////////////////////////////////////////////////
58 // SdrPage -> see continuation there
61 class SVXCORE_DLLPUBLIC SdrObjList
63 friend class SdrObjListIter
;
64 friend class SdrEditView
;
67 SdrObjList(const SdrObjList
& rSrcList
) = delete;
68 SdrObjList
&operator=(const SdrObjList
& rSrcList
) = delete;
74 /// simple ActionChildInserted forwarder to have it on a central place
75 static void impChildInserted(SdrObject
const & rChild
);
77 // tdf#116879 Clear SdrObjList, no Undo done. Used from destructor, but also
78 // from other places. When used from destructor, suppress broadcasts
79 // to not get callbacks to evtl. derived objects already in destruction
81 void impClearSdrObjList(bool bBroadcast
);
84 // protected constructor to make clear that this class should only
85 // be used as base for derivations, not naked. See getSdrModelFromSdrObjList
86 // which is pure virtual to force this, too
88 virtual ~SdrObjList();
91 // SdrModel/SdrPage access on SdrObjList level
92 virtual SdrPage
* getSdrPageFromSdrObjList() const;
93 virtual SdrObject
* getSdrObjectFromSdrObjList() const;
95 void CopyObjects(const SdrObjList
& rSrcList
);
97 // tdf#116879 clean up everything (without Undo), plus broadcasting
98 // changes. Split to this call and a private one (impClearSdrObjList)
99 // that allows cleanup without broadcasting in the destructor
100 void ClearSdrObjList();
102 /// recalculate order numbers / ZIndex
103 void RecalcObjOrdNums();
104 bool IsObjOrdNumsDirty() const { return mbObjOrdNumsDirty
; }
105 virtual void NbcInsertObject(SdrObject
* pObj
, size_t nPos
=SAL_MAX_SIZE
);
106 virtual void InsertObject(SdrObject
* pObj
, size_t nPos
=SAL_MAX_SIZE
);
107 void sort( std::vector
<sal_Int32
>& sortOrder
);
109 void InsertObjectThenMakeNameUnique(SdrObject
* pObj
);
110 void InsertObjectThenMakeNameUnique(SdrObject
* pObj
, std::unordered_set
<rtl::OUString
>& rNameSet
, size_t nPos
=SAL_MAX_SIZE
);
112 /// remove from list without delete
113 virtual rtl::Reference
<SdrObject
> NbcRemoveObject(size_t nObjNum
);
114 virtual rtl::Reference
<SdrObject
> RemoveObject(size_t nObjNum
);
116 /// Replace existing object by different one.
117 /// Same as Remove(old)+Insert(new) but faster because the order numbers
118 /// do not have to be set dirty.
119 virtual rtl::Reference
<SdrObject
> ReplaceObject(SdrObject
* pNewObj
, size_t nObjNum
);
121 /// Modify ZOrder of an SdrObject
122 virtual SdrObject
* SetObjectOrdNum(size_t nOldObjNum
, size_t nNewObjNum
);
124 /// Modify ZOrder of an SdrObject, object must already be in the list
125 void SetExistingObjectOrdNum(SdrObject
* pExistingObj
, size_t nNewObjNum
);
127 void SetSdrObjListRectsDirty();
129 const tools::Rectangle
& GetAllObjSnapRect() const;
130 const tools::Rectangle
& GetAllObjBoundRect() const;
132 /// reformat all text objects, e.g. when changing printer
133 void NbcReformatAllTextObjects();
134 void ReformatAllTextObjects();
136 /** #103122# reformats all edge objects that are connected to other objects */
137 void ReformatAllEdgeObjects();
139 /// convert attributes of the style to hard formatting
140 void BurnInStyleSheetAttributes();
142 size_t GetObjCount() const;
143 SdrObject
* GetObj(size_t nNum
) const;
144 SdrObject
* GetObjByName(std::u16string_view sName
) const;
146 /// linked page or linked group object
147 virtual bool IsReadOnly() const;
149 /** Makes the object list flat, i.e. the object list content are
152 This method travels recursively over all group objects in this
153 list, extracts the content, inserts it flat to the list and
154 removes the group object afterwards.
156 void FlattenGroups();
158 /** Ungroup the object at the given index
160 This method ungroups the content of the group object at the
161 given index, i.e. the content is put flat into the object list
162 (if the object at the given index is no group, this method is
163 a no-op). If the group itself contains group objects, the
164 operation is performed recursively, such that the content of
165 the given object contains no groups afterwards.
167 void UnGroupObj( size_t nObjNum
);
169 /** Return whether there is an explicit, user defined, object navigation
170 order. When there is one this method returns <TRUE/> and the
171 GetObjectForNavigationPosition() and
172 SdrObject::GetNavigationPosition() methods will return values
173 different from those returned by SdrObject::GetOrdNum() and
176 bool HasObjectNavigationOrder() const;
178 /** Set the navigation position of the given object to the specified
179 value. Note that this changes the navigation position for all
180 objects on or following the old or new position.
182 void SetObjectNavigationPosition (
184 const sal_uInt32 nNewNavigationPosition
);
186 /** Return the object for the given navigation position. When there is
187 a user defined navigation order, i.e. mxNavigationOrder is not NULL,
188 then that is used to look up the object. Otherwise the z-order is
189 used by looking up the object in maList.
190 @param nNavigationPosition
191 Valid values include 0 and are smaller than the number of
192 objects as returned by GetObjCount().
194 The returned pointer is NULL for invalid positions.
196 SdrObject
* GetObjectForNavigationPosition (const sal_uInt32 nNavigationPosition
) const;
198 /** Restore the navigation order to that defined by the z-order.
200 void ClearObjectNavigationOrder();
202 /** Set the navigation position of all SdrObjects to their position in
203 the mxNavigationOrder list. This method returns immediately when no
206 This method returns <TRUE/> when the navigation positions stored
207 in SdrObjects are up to date.
208 It returns <FALSE/> when the navigation positions are not valid,
209 for example because no explicit navigation order has been
210 defined, i.e. HasObjectNavigationOrder() would return <FALSE/>.
212 bool RecalcNavigationPositions();
214 /** Set the navigation order to the one defined by the given list of
217 When this is an empty reference then the navigation order is
218 reset to the z-order. The preferred way to do this, however, is
219 to call ClearObjectNavigationOrder().
220 Otherwise this list is expected to contain all the shapes in the
223 void SetNavigationOrder (const css::uno::Reference
<
224 css::container::XIndexAccess
>& rxOrder
);
226 virtual void dumpAsXml(xmlTextWriterPtr pWriter
) const;
228 typedef std::deque
<rtl::Reference
<SdrObject
>> SdrObjectDeque
;
230 SdrObjectDeque::const_iterator
begin() const { return maList
.begin(); }
231 SdrObjectDeque::const_iterator
end() const { return maList
.end(); }
232 SdrObjectDeque::const_reverse_iterator
rbegin() const { return maList
.rbegin(); }
233 SdrObjectDeque::const_reverse_iterator
rend() const { return maList
.rend(); }
236 tools::Rectangle maSdrObjListOutRect
;
237 tools::Rectangle maSdrObjListSnapRect
;
238 SdrObjectDeque maList
;
239 /// This list, if it exists, defines the navigation order. If it does
240 /// not exist then maList defines the navigation order.
241 std::optional
<std::vector
<unotools::WeakReference
<SdrObject
>>> mxNavigationOrder
;
242 bool mbObjOrdNumsDirty
;
244 /// This flag is <TRUE/> when the mpNavigation list has been changed but
245 /// the indices of the referenced SdrObjects still have their old values.
246 bool mbIsNavigationOrderDirty
;
248 /** Insert an SdrObject into maList. Do not modify the maList member
251 The object to insert into the object list.
252 @param nInsertPosition
253 The given object is inserted before the object at this
254 position. Valid values include 0 (the object is inserted at the
255 head of the list) and the number of objects in the list as
256 returned by GetObjCount() (the object is inserted at the end of
259 void InsertObjectIntoContainer (
261 const sal_uInt32 nInsertPosition
);
263 /** Replace an object in the object list.
265 The new object that replaces the one in the list at the
267 @param nObjectPosition
268 The object at this position in the object list is replaced by
269 the given object. Valid values include 0 and are smaller than
270 the number of objects in the list.
272 void ReplaceObjectInContainer (
274 const sal_uInt32 nObjectPosition
);
276 /** Remove an object from the object list.
277 The object list has to contain at least one element.
278 @param nObjectPosition
279 The object at this position is removed from the object list.
280 Valid values include 0 and are smaller than the number of
283 void RemoveObjectFromContainer (
284 const sal_uInt32 nObjectPosition
);
286 void ImplReformatAllEdgeObjects(const SdrObjList
& );
289 // Used for all methods which return a page number
290 #define SDRPAGE_NOTFOUND 0xFFFF
292 /// for the snap-to-grid in Writer
293 class SdrPageGridFrame
295 tools::Rectangle m_aPaper
;
296 tools::Rectangle m_aUserArea
;
298 SdrPageGridFrame(const tools::Rectangle
& rPaper
, const tools::Rectangle
& rUser
): m_aPaper(rPaper
), m_aUserArea(rUser
) {}
299 const tools::Rectangle
& GetPaperRect() const { return m_aPaper
; }
300 const tools::Rectangle
& GetUserArea() const { return m_aUserArea
; }
303 class SVXCORE_DLLPUBLIC SdrPageGridFrameList final
305 std::vector
<SdrPageGridFrame
*> m_aList
;
307 SdrPageGridFrameList(const SdrPageGridFrameList
& rSrcList
) = delete;
308 void operator=(const SdrPageGridFrameList
& rSrcList
) = delete;
309 SdrPageGridFrame
* GetObject(sal_uInt16 i
) const { return m_aList
[i
]; }
312 SdrPageGridFrameList() {}
313 ~SdrPageGridFrameList() { Clear(); }
315 sal_uInt16
GetCount() const { return sal_uInt16(m_aList
.size()); }
316 void Insert(const SdrPageGridFrame
& rGF
) { m_aList
.push_back(new SdrPageGridFrame(rGF
)); }
317 SdrPageGridFrame
& operator[](sal_uInt16 nPos
) { return *GetObject(nPos
); }
318 const SdrPageGridFrame
& operator[](sal_uInt16 nPos
) const { return *GetObject(nPos
); }
321 // class SdrPageProperties
322 class SVXCORE_DLLPUBLIC SdrPageProperties final
: public SfxListener
, public svl::StyleSheetUser
327 SfxStyleSheet
* mpStyleSheet
;
328 std::shared_ptr
<model::Theme
> mpTheme
;
329 SfxItemSet maProperties
;
332 void ImpRemoveStyleSheet();
333 void ImpAddStyleSheet(SfxStyleSheet
& rNewStyleSheet
);
335 SdrPageProperties
& operator=(const SdrPageProperties
& rCandidate
) = delete;
337 void sendLOKitThemeChangedCallback();
339 // construct/destruct
340 SdrPageProperties(SdrPage
& rSdrPage
);
341 virtual ~SdrPageProperties() override
;
343 // Notify(...) from baseclass SfxListener
344 virtual void Notify(SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
346 virtual bool isUsedByModel() const override
;
349 const SfxItemSet
& GetItemSet() const { return maProperties
;}
350 void PutItemSet(const SfxItemSet
& rSet
);
351 void PutItem(const SfxPoolItem
& rItem
);
352 void ClearItem(const sal_uInt16 nWhich
= 0);
355 void SetStyleSheet(SfxStyleSheet
* pStyleSheet
);
356 SfxStyleSheet
* GetStyleSheet() const { return mpStyleSheet
;}
358 void setTheme(std::shared_ptr
<model::Theme
> const& pTheme
);
359 std::shared_ptr
<model::Theme
> const& getTheme() const;
361 void dumpAsXml(xmlTextWriterPtr pWriter
) const;
366 A SdrPage contains exactly one SdrObjList and a description of the physical
367 page dimensions (size / margins). The latter is required to "catch" objects
368 during drag-and-drop.
369 The SdrPage allows (via SdrObjList) inserting and removing SdrObjects,
370 as well as moving them into the foreground or background.
371 Also it's possible to request and directly set the order number (ZOrder)
375 ////////////////////////////////////////////////////////////////////////////////////////////////////
385 class SVXCORE_DLLPUBLIC SdrPage
: public SdrObjList
, public cppu::OWeakObject
388 friend class SdrModel
;
389 friend class SvxUnoDrawPagesAccess
;
391 // this class uses its own UNO wrapper
392 // and thus has to set mxUnoPage (it also relies on mxUnoPage not being WeakRef)
393 friend class reportdesign::OSection
;
395 SdrPage
& operator=(const SdrPage
&) = delete;
396 SdrPage(const SdrPage
&) = delete;
398 // start PageUser section
400 // #111111# PageUser section
401 sdr::PageUserVector maPageUsers
;
403 std::unique_ptr
<sdr::contact::ViewContact
> mpViewContact
;
406 void AddPageUser(sdr::PageUser
& rNewUser
);
407 void RemovePageUser(sdr::PageUser
& rOldUser
);
409 // SdrModel access on SdrPage level
410 SdrModel
& getSdrModelFromSdrPage() const { return mrSdrModelFromSdrPage
; }
413 std::unique_ptr
<sdr::contact::ViewContact
> CreateObjectSpecificViewContact();
415 const sdr::contact::ViewContact
& GetViewContact() const;
416 sdr::contact::ViewContact
& GetViewContact();
418 // #110094# DrawContact support: Methods for handling Page changes
419 void ActionChanged();
422 // the SdrModel this page was created with, unchanged during SdrPage lifetime
423 SdrModel
& mrSdrModelFromSdrPage
;
426 tools::Long mnWidth
; // page size
427 tools::Long mnHeight
; // page size
428 sal_Int32 mnBorderLeft
; // left page margin
429 sal_Int32 mnBorderUpper
; // top page margin
430 sal_Int32 mnBorderRight
; // right page margin
431 sal_Int32 mnBorderLower
; // bottom page margin
432 bool mbBackgroundFullSize
= false; ///< Background object to represent the whole page.
434 std::unique_ptr
<SdrLayerAdmin
> mpLayerAdmin
;
435 std::unique_ptr
<SdrPageProperties
> mpSdrPageProperties
;
436 css::uno::Reference
< css::uno::XInterface
> mxUnoPage
;
439 SdrPageProperties
& getSdrPageProperties();
440 const SdrPageProperties
& getSdrPageProperties() const;
441 const SdrPageProperties
* getCorrectSdrPageProperties() const;
444 // new MasterPageDescriptorVector
445 std::unique_ptr
<sdr::MasterPageDescriptor
> mpMasterPageDescriptor
;
447 sal_uInt16 m_nPageNum
;
449 bool mbMaster
: 1; // flag if this is a MasterPage
451 bool mbObjectsNotPersistent
: 1;
454 bool mbPageBorderOnlyLeftRight
: 1;
456 void SetUnoPage(css::uno::Reference
<css::drawing::XDrawPage
> const&);
457 virtual css::uno::Reference
< css::uno::XInterface
> createUnoPage();
459 // Copying of pages is split into two parts: construction and copying of page objects,
460 // because the copying might need access to fully initialized page. CloneSdrPage() is responsible
461 // to call lateInit() after copy-construction of a new object. Any initialization in derived
462 // classes that needs access to the page objects must be deferred to lateInit. And it must
463 // call lateInit() of its parent class.
464 void lateInit(const SdrPage
& rSrcPage
);
467 explicit SdrPage(SdrModel
& rModel
, bool bMasterPage
=false);
468 virtual ~SdrPage() override
;
470 virtual rtl::Reference
<SdrPage
> CloneSdrPage(SdrModel
& rTargetModel
) const;
471 bool IsMasterPage() const { return mbMaster
; }
472 void SetInserted(bool bNew
= true);
473 bool IsInserted() const { return mbInserted
; }
476 // derived from SdrObjList, returns this
477 virtual SdrPage
* getSdrPageFromSdrObjList() const override
;
479 // #i68775# React on PageNum changes (from Model in most cases)
480 void SetPageNum(sal_uInt16 nNew
);
481 sal_uInt16
GetPageNum() const;
483 // #i93597# Allow page border definition to not be the full rectangle but to
484 // use only the left and right vertical edges (reportdesigner)
485 void setPageBorderOnlyLeftRight(bool bNew
) { mbPageBorderOnlyLeftRight
= bNew
; }
486 bool getPageBorderOnlyLeftRight() const { return mbPageBorderOnlyLeftRight
; }
488 virtual void SetSize(const Size
& aSiz
);
489 Size
GetSize() const;
490 virtual void SetOrientation(Orientation eOri
);
491 virtual Orientation
GetOrientation() const;
492 tools::Long
GetWidth() const;
493 tools::Long
GetHeight() const;
494 virtual void SetBorder(sal_Int32 nLft
, sal_Int32 nUpp
, sal_Int32 nRgt
, sal_Int32 Lwr
);
495 virtual void SetLeftBorder(sal_Int32 nBorder
);
496 virtual void SetUpperBorder(sal_Int32 nBorder
);
497 virtual void SetRightBorder(sal_Int32 nBorder
);
498 virtual void SetLowerBorder(sal_Int32 nBorder
);
499 sal_Int32
GetLeftBorder() const;
500 sal_Int32
GetUpperBorder() const;
501 sal_Int32
GetRightBorder() const;
502 sal_Int32
GetLowerBorder() const;
503 void SetBackgroundFullSize(bool bIn
);
504 bool IsBackgroundFullSize() const;
506 // New MasterPage interface
507 bool TRG_HasMasterPage() const { return (nullptr != mpMasterPageDescriptor
); }
508 void TRG_SetMasterPage(SdrPage
& rNew
);
509 void TRG_ClearMasterPage();
510 SdrPage
& TRG_GetMasterPage() const;
511 const SdrLayerIDSet
& TRG_GetMasterPageVisibleLayers() const;
512 void TRG_SetMasterPageVisibleLayers(const SdrLayerIDSet
& rNew
);
513 sdr::contact::ViewContact
& TRG_GetMasterPageDescriptorViewContact() const;
515 void MakePageObjectsNamesUnique();
518 void TRG_ImpMasterPageRemoved(const SdrPage
& rRemovedPage
);
521 /// changing the layers does not set the modified-flag!
522 const SdrLayerAdmin
& GetLayerAdmin() const;
523 SdrLayerAdmin
& GetLayerAdmin();
525 virtual OUString
GetLayoutName() const;
527 /// for snap-to-grid in Writer, also for AlignObjects if 1 object is marked
528 /// if pRect != null, then the pages that are intersected by this Rect,
529 /// otherwise the visible pages
530 virtual const SdrPageGridFrameList
* GetGridFrameList(const SdrPageView
* pPV
, const tools::Rectangle
* pRect
) const;
532 css::uno::Reference
< css::uno::XInterface
> const & getUnoPage();
534 virtual SfxStyleSheet
* GetTextStyleSheetForObject( SdrObject
* pObj
) const;
536 /** *deprecated* returns an averaged background color of this page */
537 // #i75566# GetBackgroundColor -> GetPageBackgroundColor
538 Color
GetPageBackgroundColor() const;
540 /** *deprecated* returns an averaged background color of this page */
541 // #i75566# GetBackgroundColor -> GetPageBackgroundColor and bScreenDisplay hint value
542 Color
GetPageBackgroundColor( SdrPageView
const * pView
, bool bScreenDisplay
= true) const;
544 /** this method returns true if the object from the ViewObjectContact should
545 be visible on this page while rendering.
546 bEdit selects if visibility test is for an editing view or a final render,
549 virtual bool checkVisibility(
550 const sdr::contact::ViewObjectContact
& rOriginal
,
551 const sdr::contact::DisplayInfo
& rDisplayInfo
,
554 void dumpAsXml(xmlTextWriterPtr pWriter
) const override
;
557 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */