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;
229 tools::Rectangle maSdrObjListOutRect
;
230 tools::Rectangle maSdrObjListSnapRect
;
231 std::deque
<rtl::Reference
<SdrObject
>> maList
;
232 /// This list, if it exists, defines the navigation order. If it does
233 /// not exist then maList defines the navigation order.
234 std::optional
<std::vector
<unotools::WeakReference
<SdrObject
>>> mxNavigationOrder
;
235 bool mbObjOrdNumsDirty
;
237 /// This flag is <TRUE/> when the mpNavigation list has been changed but
238 /// the indices of the referenced SdrObjects still have their old values.
239 bool mbIsNavigationOrderDirty
;
241 /** Insert an SdrObject into maList. Do not modify the maList member
244 The object to insert into the object list.
245 @param nInsertPosition
246 The given object is inserted before the object at this
247 position. Valid values include 0 (the object is inserted at the
248 head of the list) and the number of objects in the list as
249 returned by GetObjCount() (the object is inserted at the end of
252 void InsertObjectIntoContainer (
254 const sal_uInt32 nInsertPosition
);
256 /** Replace an object in the object list.
258 The new object that replaces the one in the list at the
260 @param nObjectPosition
261 The object at this position in the object list is replaced by
262 the given object. Valid values include 0 and are smaller than
263 the number of objects in the list.
265 void ReplaceObjectInContainer (
267 const sal_uInt32 nObjectPosition
);
269 /** Remove an object from the object list.
270 The object list has to contain at least one element.
271 @param nObjectPosition
272 The object at this position is removed from the object list.
273 Valid values include 0 and are smaller than the number of
276 void RemoveObjectFromContainer (
277 const sal_uInt32 nObjectPosition
);
279 void ImplReformatAllEdgeObjects(const SdrObjList
& );
282 // Used for all methods which return a page number
283 #define SDRPAGE_NOTFOUND 0xFFFF
285 /// for the snap-to-grid in Writer
286 class SdrPageGridFrame
288 tools::Rectangle aPaper
;
289 tools::Rectangle aUserArea
;
291 SdrPageGridFrame(const tools::Rectangle
& rPaper
, const tools::Rectangle
& rUser
): aPaper(rPaper
), aUserArea(rUser
) {}
292 const tools::Rectangle
& GetPaperRect() const { return aPaper
; }
293 const tools::Rectangle
& GetUserArea() const { return aUserArea
; }
296 class SVXCORE_DLLPUBLIC SdrPageGridFrameList final
298 std::vector
<SdrPageGridFrame
*> aList
;
300 SdrPageGridFrameList(const SdrPageGridFrameList
& rSrcList
) = delete;
301 void operator=(const SdrPageGridFrameList
& rSrcList
) = delete;
302 SdrPageGridFrame
* GetObject(sal_uInt16 i
) const { return aList
[i
]; }
305 SdrPageGridFrameList() {}
306 ~SdrPageGridFrameList() { Clear(); }
308 sal_uInt16
GetCount() const { return sal_uInt16(aList
.size()); }
309 void Insert(const SdrPageGridFrame
& rGF
) { aList
.push_back(new SdrPageGridFrame(rGF
)); }
310 SdrPageGridFrame
& operator[](sal_uInt16 nPos
) { return *GetObject(nPos
); }
311 const SdrPageGridFrame
& operator[](sal_uInt16 nPos
) const { return *GetObject(nPos
); }
314 // class SdrPageProperties
315 class SVXCORE_DLLPUBLIC SdrPageProperties final
: public SfxListener
, public svl::StyleSheetUser
320 SfxStyleSheet
* mpStyleSheet
;
321 std::shared_ptr
<model::Theme
> mpTheme
;
322 SfxItemSet maProperties
;
325 void ImpRemoveStyleSheet();
326 void ImpAddStyleSheet(SfxStyleSheet
& rNewStyleSheet
);
328 SdrPageProperties
& operator=(const SdrPageProperties
& rCandidate
) = delete;
330 void sendLOKitThemeChangedCallback();
332 // construct/destruct
333 SdrPageProperties(SdrPage
& rSdrPage
);
334 virtual ~SdrPageProperties() override
;
336 // Notify(...) from baseclass SfxListener
337 virtual void Notify(SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
339 virtual bool isUsedByModel() const override
;
342 const SfxItemSet
& GetItemSet() const { return maProperties
;}
343 void PutItemSet(const SfxItemSet
& rSet
);
344 void PutItem(const SfxPoolItem
& rItem
);
345 void ClearItem(const sal_uInt16 nWhich
= 0);
348 void SetStyleSheet(SfxStyleSheet
* pStyleSheet
);
349 SfxStyleSheet
* GetStyleSheet() const { return mpStyleSheet
;}
351 void SetTheme(std::shared_ptr
<model::Theme
> const& pTheme
);
352 std::shared_ptr
<model::Theme
> const& GetTheme() const;
354 void dumpAsXml(xmlTextWriterPtr pWriter
) const;
359 A SdrPage contains exactly one SdrObjList and a description of the physical
360 page dimensions (size / margins). The latter is required to "catch" objects
361 during drag-and-drop.
362 The SdrPage allows (via SdrObjList) inserting and removing SdrObjects,
363 as well as moving them into the foreground or background.
364 Also it's possible to request and directly set the order number (ZOrder)
368 ////////////////////////////////////////////////////////////////////////////////////////////////////
378 class SVXCORE_DLLPUBLIC SdrPage
: public SdrObjList
, public cppu::OWeakObject
381 friend class SdrModel
;
382 friend class SvxUnoDrawPagesAccess
;
384 // this class uses its own UNO wrapper
385 // and thus has to set mxUnoPage (it also relies on mxUnoPage not being WeakRef)
386 friend class reportdesign::OSection
;
388 SdrPage
& operator=(const SdrPage
&) = delete;
389 SdrPage(const SdrPage
&) = delete;
391 // start PageUser section
393 // #111111# PageUser section
394 sdr::PageUserVector maPageUsers
;
396 std::unique_ptr
<sdr::contact::ViewContact
> mpViewContact
;
399 void AddPageUser(sdr::PageUser
& rNewUser
);
400 void RemovePageUser(sdr::PageUser
& rOldUser
);
402 // SdrModel access on SdrPage level
403 SdrModel
& getSdrModelFromSdrPage() const { return mrSdrModelFromSdrPage
; }
406 std::unique_ptr
<sdr::contact::ViewContact
> CreateObjectSpecificViewContact();
408 const sdr::contact::ViewContact
& GetViewContact() const;
409 sdr::contact::ViewContact
& GetViewContact();
411 // #110094# DrawContact support: Methods for handling Page changes
412 void ActionChanged();
415 // the SdrModel this page was created with, unchanged during SdrPage lifetime
416 SdrModel
& mrSdrModelFromSdrPage
;
419 tools::Long mnWidth
; // page size
420 tools::Long mnHeight
; // page size
421 sal_Int32 mnBorderLeft
; // left page margin
422 sal_Int32 mnBorderUpper
; // top page margin
423 sal_Int32 mnBorderRight
; // right page margin
424 sal_Int32 mnBorderLower
; // bottom page margin
425 bool mbBackgroundFullSize
= false; ///< Background object to represent the whole page.
427 std::unique_ptr
<SdrLayerAdmin
> mpLayerAdmin
;
428 std::unique_ptr
<SdrPageProperties
> mpSdrPageProperties
;
429 css::uno::Reference
< css::uno::XInterface
> mxUnoPage
;
432 SdrPageProperties
& getSdrPageProperties();
433 const SdrPageProperties
& getSdrPageProperties() const;
434 const SdrPageProperties
* getCorrectSdrPageProperties() const;
437 // new MasterPageDescriptorVector
438 std::unique_ptr
<sdr::MasterPageDescriptor
> mpMasterPageDescriptor
;
442 bool mbMaster
: 1; // flag if this is a MasterPage
444 bool mbObjectsNotPersistent
: 1;
447 bool mbPageBorderOnlyLeftRight
: 1;
449 void SetUnoPage(css::uno::Reference
<css::drawing::XDrawPage
> const&);
450 virtual css::uno::Reference
< css::uno::XInterface
> createUnoPage();
452 // Copying of pages is split into two parts: construction and copying of page objects,
453 // because the copying might need access to fully initialized page. CloneSdrPage() is responsible
454 // to call lateInit() after copy-construction of a new object. Any initialization in derived
455 // classes that needs access to the page objects must be deferred to lateInit. And it must
456 // call lateInit() of its parent class.
457 void lateInit(const SdrPage
& rSrcPage
);
460 explicit SdrPage(SdrModel
& rModel
, bool bMasterPage
=false);
461 virtual ~SdrPage() override
;
463 virtual rtl::Reference
<SdrPage
> CloneSdrPage(SdrModel
& rTargetModel
) const;
464 bool IsMasterPage() const { return mbMaster
; }
465 void SetInserted(bool bNew
= true);
466 bool IsInserted() const { return mbInserted
; }
469 // derived from SdrObjList, returns this
470 virtual SdrPage
* getSdrPageFromSdrObjList() const override
;
472 // #i68775# React on PageNum changes (from Model in most cases)
473 void SetPageNum(sal_uInt16 nNew
);
474 sal_uInt16
GetPageNum() const;
476 // #i93597# Allow page border definition to not be the full rectangle but to
477 // use only the left and right vertical edges (reportdesigner)
478 void setPageBorderOnlyLeftRight(bool bNew
) { mbPageBorderOnlyLeftRight
= bNew
; }
479 bool getPageBorderOnlyLeftRight() const { return mbPageBorderOnlyLeftRight
; }
481 virtual void SetSize(const Size
& aSiz
);
482 Size
GetSize() const;
483 virtual void SetOrientation(Orientation eOri
);
484 virtual Orientation
GetOrientation() const;
485 tools::Long
GetWidth() const;
486 tools::Long
GetHeight() const;
487 virtual void SetBorder(sal_Int32 nLft
, sal_Int32 nUpp
, sal_Int32 nRgt
, sal_Int32 Lwr
);
488 virtual void SetLeftBorder(sal_Int32 nBorder
);
489 virtual void SetUpperBorder(sal_Int32 nBorder
);
490 virtual void SetRightBorder(sal_Int32 nBorder
);
491 virtual void SetLowerBorder(sal_Int32 nBorder
);
492 sal_Int32
GetLeftBorder() const;
493 sal_Int32
GetUpperBorder() const;
494 sal_Int32
GetRightBorder() const;
495 sal_Int32
GetLowerBorder() const;
496 void SetBackgroundFullSize(bool bIn
);
497 bool IsBackgroundFullSize() const;
499 // New MasterPage interface
500 bool TRG_HasMasterPage() const { return (nullptr != mpMasterPageDescriptor
); }
501 void TRG_SetMasterPage(SdrPage
& rNew
);
502 void TRG_ClearMasterPage();
503 SdrPage
& TRG_GetMasterPage() const;
504 const SdrLayerIDSet
& TRG_GetMasterPageVisibleLayers() const;
505 void TRG_SetMasterPageVisibleLayers(const SdrLayerIDSet
& rNew
);
506 sdr::contact::ViewContact
& TRG_GetMasterPageDescriptorViewContact() const;
508 void MakePageObjectsNamesUnique();
511 void TRG_ImpMasterPageRemoved(const SdrPage
& rRemovedPage
);
514 /// changing the layers does not set the modified-flag!
515 const SdrLayerAdmin
& GetLayerAdmin() const;
516 SdrLayerAdmin
& GetLayerAdmin();
518 virtual OUString
GetLayoutName() const;
520 /// for snap-to-grid in Writer, also for AlignObjects if 1 object is marked
521 /// if pRect != null, then the pages that are intersected by this Rect,
522 /// otherwise the visible pages
523 virtual const SdrPageGridFrameList
* GetGridFrameList(const SdrPageView
* pPV
, const tools::Rectangle
* pRect
) const;
525 css::uno::Reference
< css::uno::XInterface
> const & getUnoPage();
527 virtual SfxStyleSheet
* GetTextStyleSheetForObject( SdrObject
* pObj
) const;
529 /** *deprecated* returns an averaged background color of this page */
530 // #i75566# GetBackgroundColor -> GetPageBackgroundColor
531 Color
GetPageBackgroundColor() const;
533 /** *deprecated* returns an averaged background color of this page */
534 // #i75566# GetBackgroundColor -> GetPageBackgroundColor and bScreenDisplay hint value
535 Color
GetPageBackgroundColor( SdrPageView
const * pView
, bool bScreenDisplay
= true) const;
537 /** this method returns true if the object from the ViewObjectContact should
538 be visible on this page while rendering.
539 bEdit selects if visibility test is for an editing view or a final render,
542 virtual bool checkVisibility(
543 const sdr::contact::ViewObjectContact
& rOriginal
,
544 const sdr::contact::DisplayInfo
& rDisplayInfo
,
547 void dumpAsXml(xmlTextWriterPtr pWriter
) const override
;
550 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */