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_SVX_SVDPAGE_HXX
21 #define INCLUDED_SVX_SVDPAGE_HXX
23 #include <svl/stylesheetuser.hxx>
24 #include <vcl/prntypes.hxx>
25 #include <tools/weakbase.h>
26 #include <svl/itemset.hxx>
27 #include <svx/sdrpageuser.hxx>
28 #include <svx/sdr/contact/viewobjectcontactredirector.hxx>
29 #include <svx/sdrmasterpagedescriptor.hxx>
30 #include <svx/svxdllapi.h>
31 #include <com/sun/star/container/XIndexAccess.hpp>
32 #include <com/sun/star/drawing/XDrawPage.hpp>
33 #include <svx/svdobj.hxx>
39 namespace reportdesign
{ class OSection
; }
40 namespace sdr::contact
{ class ViewContact
; }
49 class SvxUnoDrawPagesAccess
;
51 ////////////////////////////////////////////////////////////////////////////////////////////////////
55 // SdrPage -> see continuation there
58 class SVXCORE_DLLPUBLIC SdrObjList
60 friend class SdrObjListIter
;
61 friend class SdrEditView
;
64 SdrObjList(const SdrObjList
& rSrcList
) = delete;
65 SdrObjList
&operator=(const SdrObjList
& rSrcList
) = delete;
67 ::std::vector
<SdrObject
*> maList
;
69 tools::Rectangle maSdrObjListOutRect
;
70 tools::Rectangle maSdrObjListSnapRect
;
71 bool mbObjOrdNumsDirty
;
78 /// simple ActionChildInserted forwarder to have it on a central place
79 static void impChildInserted(SdrObject
const & rChild
);
81 // tdf#116879 Clear SdrObjList, no Undo done. Used from destructor, but also
82 // from other places. When used from destructor, suppress broadcasts
83 // to not get callbacks to evtl. derived objects already in destruction
85 void impClearSdrObjList(bool bBroadcast
);
88 // protected constructor to make clear that this class should only
89 // be used as base for derivations, not naked. See getSdrModelFromSdrObjList
90 // which is pure virtual to force this, too
92 virtual ~SdrObjList();
95 // SdrModel/SdrPage access on SdrObjList level
96 virtual SdrPage
* getSdrPageFromSdrObjList() const;
97 virtual SdrObject
* getSdrObjectFromSdrObjList() const;
99 void CopyObjects(const SdrObjList
& rSrcList
);
101 // tdf#116879 clean up everything (without Undo), plus broadcasting
102 // changes. Split to this call and a private one (impClearSdrObjList)
103 // that allows cleanup without broadcasting in the destructor
104 void ClearSdrObjList();
106 /// recalculate order numbers / ZIndex
107 void RecalcObjOrdNums();
108 bool IsObjOrdNumsDirty() const { return mbObjOrdNumsDirty
; }
109 virtual void NbcInsertObject(SdrObject
* pObj
, size_t nPos
=SAL_MAX_SIZE
);
110 virtual void InsertObject(SdrObject
* pObj
, size_t nPos
=SAL_MAX_SIZE
);
111 void sort( std::vector
<sal_Int32
>& sortOrder
);
113 void InsertObjectThenMakeNameUnique(SdrObject
* pObj
);
114 void InsertObjectThenMakeNameUnique(SdrObject
* pObj
, std::unordered_set
<rtl::OUString
>& rNameSet
, size_t nPos
=SAL_MAX_SIZE
);
116 /// remove from list without delete
117 virtual SdrObject
* NbcRemoveObject(size_t nObjNum
);
118 virtual SdrObject
* RemoveObject(size_t nObjNum
);
120 /// Replace existing object by different one.
121 /// Same as Remove(old)+Insert(new) but faster because the order numbers
122 /// do not have to be set dirty.
123 virtual SdrObject
* ReplaceObject(SdrObject
* pNewObj
, size_t nObjNum
);
125 /// Modify ZOrder of an SdrObject
126 virtual SdrObject
* SetObjectOrdNum(size_t nOldObjNum
, size_t nNewObjNum
);
128 void SetSdrObjListRectsDirty();
130 const tools::Rectangle
& GetAllObjSnapRect() const;
131 const tools::Rectangle
& GetAllObjBoundRect() const;
133 /// reformat all text objects, e.g. when changing printer
134 void NbcReformatAllTextObjects();
135 void ReformatAllTextObjects();
137 /** #103122# reformats all edge objects that are connected to other objects */
138 void ReformatAllEdgeObjects();
140 /// convert attributes of the style to hard formatting
141 void BurnInStyleSheetAttributes();
143 size_t GetObjCount() const;
144 SdrObject
* GetObj(size_t nNum
) 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 /// This list, if it exists, defines the navigation order. If it does
230 /// not exist then maList defines the navigation order.
231 std::unique_ptr
<std::vector
<tools::WeakReference
<SdrObject
>>> mxNavigationOrder
;
233 /// This flag is <TRUE/> when the mpNavigation list has been changed but
234 /// the indices of the referenced SdrObjects still have their old values.
235 bool mbIsNavigationOrderDirty
;
237 /** Insert an SdrObject into maList. Do not modify the maList member
240 The object to insert into the object list.
241 @param nInsertPosition
242 The given object is inserted before the object at this
243 position. Valid values include 0 (the object is inserted at the
244 head of the list) and the number of objects in the list as
245 returned by GetObjCount() (the object is inserted at the end of
248 void InsertObjectIntoContainer (
250 const sal_uInt32 nInsertPosition
);
252 /** Replace an object in the object list.
254 The new object that replaces the one in the list at the
256 @param nObjectPosition
257 The object at this position in the object list is replaced by
258 the given object. Valid values include 0 and are smaller than
259 the number of objects in the list.
261 void ReplaceObjectInContainer (
263 const sal_uInt32 nObjectPosition
);
265 /** Remove an object from the object list.
266 The object list has to contain at least one element.
267 @param nObjectPosition
268 The object at this position is removed from the object list.
269 Valid values include 0 and are smaller than the number of
272 void RemoveObjectFromContainer (
273 const sal_uInt32 nObjectPosition
);
276 // Used for all methods which return a page number
277 #define SDRPAGE_NOTFOUND 0xFFFF
279 /// for the snap-to-grid in Writer
280 class SdrPageGridFrame
282 tools::Rectangle aPaper
;
283 tools::Rectangle aUserArea
;
285 SdrPageGridFrame(const tools::Rectangle
& rPaper
, const tools::Rectangle
& rUser
): aPaper(rPaper
), aUserArea(rUser
) {}
286 const tools::Rectangle
& GetPaperRect() const { return aPaper
; }
287 const tools::Rectangle
& GetUserArea() const { return aUserArea
; }
290 class SVXCORE_DLLPUBLIC SdrPageGridFrameList final
292 std::vector
<SdrPageGridFrame
*> aList
;
294 SdrPageGridFrameList(const SdrPageGridFrameList
& rSrcList
) = delete;
295 void operator=(const SdrPageGridFrameList
& rSrcList
) = delete;
296 SdrPageGridFrame
* GetObject(sal_uInt16 i
) const { return aList
[i
]; }
299 SdrPageGridFrameList(): aList() {}
300 ~SdrPageGridFrameList() { Clear(); }
302 sal_uInt16
GetCount() const { return sal_uInt16(aList
.size()); }
303 void Insert(const SdrPageGridFrame
& rGF
) { aList
.push_back(new SdrPageGridFrame(rGF
)); }
304 SdrPageGridFrame
& operator[](sal_uInt16 nPos
) { return *GetObject(nPos
); }
305 const SdrPageGridFrame
& operator[](sal_uInt16 nPos
) const { return *GetObject(nPos
); }
308 // class SdrPageProperties
309 class SVXCORE_DLLPUBLIC SdrPageProperties
: public SfxListener
, public svl::StyleSheetUser
314 SfxStyleSheet
* mpStyleSheet
;
315 SfxItemSet maProperties
;
318 void ImpRemoveStyleSheet();
319 void ImpAddStyleSheet(SfxStyleSheet
& rNewStyleSheet
);
321 SdrPageProperties
& operator=(const SdrPageProperties
& rCandidate
) = delete;
324 // construct/destruct
325 SdrPageProperties(SdrPage
& rSdrPage
);
326 virtual ~SdrPageProperties() override
;
328 // Notify(...) from baseclass SfxListener
329 virtual void Notify(SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
331 virtual bool isUsedByModel() const override
;
334 const SfxItemSet
& GetItemSet() const { return maProperties
;}
335 void PutItemSet(const SfxItemSet
& rSet
);
336 void PutItem(const SfxPoolItem
& rItem
);
337 void ClearItem(const sal_uInt16 nWhich
= 0);
340 void SetStyleSheet(SfxStyleSheet
* pStyleSheet
);
341 SfxStyleSheet
* GetStyleSheet() const { return mpStyleSheet
;}
346 A SdrPage contains exactly one SdrObjList and a description of the physical
347 page dimensions (size / margins). The latter is required to "catch" objects
348 during drag-and-drop.
349 The SdrPage allows (via SdrObjList) inserting and removing SdrObjects,
350 as well as moving them into the foreground or background.
351 Also it's possible to request and directly set the order number (ZOrder)
355 ////////////////////////////////////////////////////////////////////////////////////////////////////
365 class SVXCORE_DLLPUBLIC SdrPage
: public SdrObjList
, public tools::WeakBase
368 friend class SdrModel
;
369 friend class SvxUnoDrawPagesAccess
;
371 // this class uses its own UNO wrapper
372 // and thus has to set mxUnoPage (it also relies on mxUnoPage not being WeakRef)
373 friend class reportdesign::OSection
;
375 SdrPage
& operator=(const SdrPage
&) = delete;
376 SdrPage(const SdrPage
&) = delete;
378 // start PageUser section
380 // #111111# PageUser section
381 sdr::PageUserVector maPageUsers
;
383 std::unique_ptr
<sdr::contact::ViewContact
> mpViewContact
;
386 void AddPageUser(sdr::PageUser
& rNewUser
);
387 void RemovePageUser(sdr::PageUser
& rOldUser
);
389 // SdrModel access on SdrPage level
390 SdrModel
& getSdrModelFromSdrPage() const { return mrSdrModelFromSdrPage
; }
393 std::unique_ptr
<sdr::contact::ViewContact
> CreateObjectSpecificViewContact();
395 const sdr::contact::ViewContact
& GetViewContact() const;
396 sdr::contact::ViewContact
& GetViewContact();
398 // #110094# DrawContact support: Methods for handling Page changes
399 void ActionChanged();
402 // the SdrModel this page was created with, unchanged during SdrPage lifetime
403 SdrModel
& mrSdrModelFromSdrPage
;
406 sal_Int32 mnWidth
; // page size
407 sal_Int32 mnHeight
; // page size
408 sal_Int32 mnBorderLeft
; // left page margin
409 sal_Int32 mnBorderUpper
; // top page margin
410 sal_Int32 mnBorderRight
; // right page margin
411 sal_Int32 mnBorderLower
; // bottom page margin
413 std::unique_ptr
<SdrLayerAdmin
> mpLayerAdmin
;
414 std::unique_ptr
<SdrPageProperties
> mpSdrPageProperties
;
415 css::uno::Reference
< css::uno::XInterface
> mxUnoPage
;
418 SdrPageProperties
& getSdrPageProperties();
419 const SdrPageProperties
& getSdrPageProperties() const;
420 const SdrPageProperties
* getCorrectSdrPageProperties() const;
423 // new MasterPageDescriptorVector
424 std::unique_ptr
<sdr::MasterPageDescriptor
> mpMasterPageDescriptor
;
428 bool mbMaster
: 1; // flag if this is a MasterPage
430 bool mbObjectsNotPersistent
: 1;
433 bool mbPageBorderOnlyLeftRight
: 1;
435 void SetUnoPage(css::uno::Reference
<css::drawing::XDrawPage
> const&);
436 virtual css::uno::Reference
< css::uno::XInterface
> createUnoPage();
438 // Copying of pages is split into two parts: construction and copying of page objects,
439 // because the copying might need access to fully initialized page. CloneSdrPage() is responsible
440 // to call lateInit() after copy-construction of a new object. Any initialization in derived
441 // classes that needs access to the page objects must be deferred to lateInit. And it must
442 // call lateInit() of its parent class.
443 void lateInit(const SdrPage
& rSrcPage
);
446 explicit SdrPage(SdrModel
& rModel
, bool bMasterPage
=false);
447 virtual ~SdrPage() override
;
449 virtual SdrPage
* CloneSdrPage(SdrModel
& rTargetModel
) const;
450 bool IsMasterPage() const { return mbMaster
; }
451 void SetInserted(bool bNew
= true);
452 bool IsInserted() const { return mbInserted
; }
455 // derived from SdrObjList, returns this
456 virtual SdrPage
* getSdrPageFromSdrObjList() const override
;
458 // #i68775# React on PageNum changes (from Model in most cases)
459 void SetPageNum(sal_uInt16 nNew
);
460 sal_uInt16
GetPageNum() const;
462 // #i93597# Allow page border definition to not be the full rectangle but to
463 // use only the left and right vertical edges (reportdesigner)
464 void setPageBorderOnlyLeftRight(bool bNew
) { mbPageBorderOnlyLeftRight
= bNew
; }
465 bool getPageBorderOnlyLeftRight() const { return mbPageBorderOnlyLeftRight
; }
467 virtual void SetSize(const Size
& aSiz
);
468 Size
GetSize() const;
469 virtual void SetOrientation(Orientation eOri
);
470 virtual Orientation
GetOrientation() const;
471 sal_Int32
GetWidth() const;
472 sal_Int32
GetHeight() const;
473 virtual void SetBorder(sal_Int32 nLft
, sal_Int32 nUpp
, sal_Int32 nRgt
, sal_Int32 Lwr
);
474 virtual void SetLeftBorder(sal_Int32 nBorder
);
475 virtual void SetUpperBorder(sal_Int32 nBorder
);
476 virtual void SetRightBorder(sal_Int32 nBorder
);
477 virtual void SetLowerBorder(sal_Int32 nBorder
);
478 sal_Int32
GetLeftBorder() const;
479 sal_Int32
GetUpperBorder() const;
480 sal_Int32
GetRightBorder() const;
481 sal_Int32
GetLowerBorder() const;
483 // New MasterPage interface
484 bool TRG_HasMasterPage() const { return (nullptr != mpMasterPageDescriptor
); }
485 void TRG_SetMasterPage(SdrPage
& rNew
);
486 void TRG_ClearMasterPage();
487 SdrPage
& TRG_GetMasterPage() const;
488 const SdrLayerIDSet
& TRG_GetMasterPageVisibleLayers() const;
489 void TRG_SetMasterPageVisibleLayers(const SdrLayerIDSet
& rNew
);
490 sdr::contact::ViewContact
& TRG_GetMasterPageDescriptorViewContact() const;
492 void MakePageObjectsNamesUnique();
495 void TRG_ImpMasterPageRemoved(const SdrPage
& rRemovedPage
);
498 /// changing the layers does not set the modified-flag!
499 const SdrLayerAdmin
& GetLayerAdmin() const;
500 SdrLayerAdmin
& GetLayerAdmin();
502 virtual OUString
GetLayoutName() const;
504 /// for snap-to-grid in Writer, also for AlignObjects if 1 object is marked
505 /// if pRect != null, then the pages that are intersected by this Rect,
506 /// otherwise the visible pages
507 virtual const SdrPageGridFrameList
* GetGridFrameList(const SdrPageView
* pPV
, const tools::Rectangle
* pRect
) const;
509 css::uno::Reference
< css::uno::XInterface
> const & getUnoPage();
511 virtual SfxStyleSheet
* GetTextStyleSheetForObject( SdrObject
* pObj
) const;
513 /** *deprecated* returns an averaged background color of this page */
514 // #i75566# GetBackgroundColor -> GetPageBackgroundColor
515 Color
GetPageBackgroundColor() const;
517 /** *deprecated* returns an averaged background color of this page */
518 // #i75566# GetBackgroundColor -> GetPageBackgroundColor and bScreenDisplay hint value
519 Color
GetPageBackgroundColor( SdrPageView
const * pView
, bool bScreenDisplay
= true) const;
521 /** this method returns true if the object from the ViewObjectContact should
522 be visible on this page while rendering.
523 bEdit selects if visibility test is for an editing view or a final render,
526 virtual bool checkVisibility(
527 const sdr::contact::ViewObjectContact
& rOriginal
,
528 const sdr::contact::DisplayInfo
& rDisplayInfo
,
533 #endif // INCLUDED_SVX_SVDPAGE_HXX
535 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */