Bump version to 6.4-15
[LibreOffice.git] / include / svx / svdpage.hxx
blobcfdea335ee1ddf07421d400e09882b1d4b569c1e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
34 #include <memory>
35 #include <vector>
38 // predefines
39 namespace reportdesign { class OSection; }
40 namespace sdr { namespace contact { class ViewContact; }}
41 class SdrPage;
42 class SdrModel;
43 class SfxItemPool;
44 class SdrPageView;
45 class SdrLayerAdmin;
46 class SdrLayerIDSet;
47 class Color;
48 class SfxStyleSheet;
49 class SvxUnoDrawPagesAccess;
51 ////////////////////////////////////////////////////////////////////////////////////////////////////
53 // SdrObjList
54 // E3dObjList
55 // SdrPage -> see continuation there
57 // class SdrObjList
58 class SVX_DLLPUBLIC SdrObjList
60 friend class SdrObjListIter;
61 friend class SdrEditView;
63 private:
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;
72 bool mbRectsDirty;
74 protected:
75 void RecalcRects();
77 private:
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
84 // (e.g. SdrPage)
85 void impClearSdrObjList(bool bBroadcast);
87 protected:
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
91 SdrObjList();
92 virtual ~SdrObjList();
94 public:
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
150 then tree leaves
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
174 GetObj().
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 (
183 SdrObject& rObject,
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().
193 @return
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
204 update is necessary.
205 @return
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
215 XShape objects.
216 @param rxOrder
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
221 called SdrObjList.
223 void SetNavigationOrder (const css::uno::Reference<
224 css::container::XIndexAccess>& rxOrder);
226 virtual void dumpAsXml(xmlTextWriterPtr pWriter) const;
228 private:
229 class WeakSdrObjectContainerType;
230 /// This list, if it exists, defines the navigation order. If it does
231 /// not exist then maList defines the navigation order.
232 std::unique_ptr<WeakSdrObjectContainerType> mxNavigationOrder;
234 /// This flag is <TRUE/> when the mpNavigation list has been changed but
235 /// the indices of the referenced SdrObjects still have their old values.
236 bool mbIsNavigationOrderDirty;
238 /** Insert an SdrObject into maList. Do not modify the maList member
239 directly.
240 @param rObject
241 The object to insert into the object list.
242 @param nInsertPosition
243 The given object is inserted before the object at this
244 position. Valid values include 0 (the object is inserted at the
245 head of the list) and the number of objects in the list as
246 returned by GetObjCount() (the object is inserted at the end of
247 the list.)
249 void InsertObjectIntoContainer (
250 SdrObject& rObject,
251 const sal_uInt32 nInsertPosition);
253 /** Replace an object in the object list.
254 @param rObject
255 The new object that replaces the one in the list at the
256 specified position.
257 @param nObjectPosition
258 The object at this position in the object list is replaced by
259 the given object. Valid values include 0 and are smaller than
260 the number of objects in the list.
262 void ReplaceObjectInContainer (
263 SdrObject& rObject,
264 const sal_uInt32 nObjectPosition);
266 /** Remove an object from the object list.
267 The object list has to contain at least one element.
268 @param nObjectPosition
269 The object at this position is removed from the object list.
270 Valid values include 0 and are smaller than the number of
271 objects in the list.
273 void RemoveObjectFromContainer (
274 const sal_uInt32 nObjectPosition);
277 // Used for all methods which return a page number
278 #define SDRPAGE_NOTFOUND 0xFFFF
280 /// for the snap-to-grid in Writer
281 class SdrPageGridFrame
283 tools::Rectangle const aPaper;
284 tools::Rectangle const aUserArea;
285 public:
286 SdrPageGridFrame(const tools::Rectangle& rPaper, const tools::Rectangle& rUser): aPaper(rPaper), aUserArea(rUser) {}
287 const tools::Rectangle& GetPaperRect() const { return aPaper; }
288 const tools::Rectangle& GetUserArea() const { return aUserArea; }
291 class SVX_DLLPUBLIC SdrPageGridFrameList final
293 std::vector<SdrPageGridFrame*> aList;
295 SdrPageGridFrameList(const SdrPageGridFrameList& rSrcList) = delete;
296 void operator=(const SdrPageGridFrameList& rSrcList) = delete;
297 SdrPageGridFrame* GetObject(sal_uInt16 i) const { return aList[i]; }
299 public:
300 SdrPageGridFrameList(): aList() {}
301 ~SdrPageGridFrameList() { Clear(); }
302 void Clear();
303 sal_uInt16 GetCount() const { return sal_uInt16(aList.size()); }
304 void Insert(const SdrPageGridFrame& rGF) { aList.push_back(new SdrPageGridFrame(rGF)); }
305 SdrPageGridFrame& operator[](sal_uInt16 nPos) { return *GetObject(nPos); }
306 const SdrPageGridFrame& operator[](sal_uInt16 nPos) const { return *GetObject(nPos); }
309 // class SdrPageProperties
310 class SVX_DLLPUBLIC SdrPageProperties : public SfxListener, public svl::StyleSheetUser
312 private:
313 // data
314 SdrPage* mpSdrPage;
315 SfxStyleSheet* mpStyleSheet;
316 SfxItemSet maProperties;
318 // internal helpers
319 void ImpRemoveStyleSheet();
320 void ImpAddStyleSheet(SfxStyleSheet& rNewStyleSheet);
322 SdrPageProperties& operator=(const SdrPageProperties& rCandidate) = delete;
324 public:
325 // construct/destruct
326 SdrPageProperties(SdrPage& rSdrPage);
327 virtual ~SdrPageProperties() override;
329 // Notify(...) from baseclass SfxListener
330 virtual void Notify(SfxBroadcaster& rBC, const SfxHint& rHint) override;
332 virtual bool isUsedByModel() const override;
334 // data read/write
335 const SfxItemSet& GetItemSet() const { return maProperties;}
336 void PutItemSet(const SfxItemSet& rSet);
337 void PutItem(const SfxPoolItem& rItem);
338 void ClearItem(const sal_uInt16 nWhich = 0);
340 // StyleSheet access
341 void SetStyleSheet(SfxStyleSheet* pStyleSheet);
342 SfxStyleSheet* GetStyleSheet() const { return mpStyleSheet;}
347 A SdrPage contains exactly one SdrObjList and a description of the physical
348 page dimensions (size / margins). The latter is required to "catch" objects
349 during drag-and-drop.
350 The SdrPage allows (via SdrObjList) inserting and removing SdrObjects,
351 as well as moving them into the foreground or background.
352 Also it's possible to request and directly set the order number (ZOrder)
353 of SdrObjects.
356 ////////////////////////////////////////////////////////////////////////////////////////////////////
358 // SdrPage
359 // DlgEdPage
360 // FmFormPage
361 // ScDrawPage
362 // SdPage
363 // SwDPage
364 // OReportPage
366 class SVX_DLLPUBLIC SdrPage : public SdrObjList, public tools::WeakBase
368 // #i9076#
369 friend class SdrModel;
370 friend class SvxUnoDrawPagesAccess;
372 // this class uses its own UNO wrapper
373 // and thus has to set mxUnoPage (it also relies on mxUnoPage not being WeakRef)
374 friend class reportdesign::OSection;
376 SdrPage& operator=(const SdrPage&) = delete;
377 SdrPage(const SdrPage&) = delete;
379 // start PageUser section
380 private:
381 // #111111# PageUser section
382 sdr::PageUserVector maPageUsers;
384 std::unique_ptr<sdr::contact::ViewContact> mpViewContact;
386 public:
387 void AddPageUser(sdr::PageUser& rNewUser);
388 void RemovePageUser(sdr::PageUser& rOldUser);
390 // SdrModel access on SdrPage level
391 SdrModel& getSdrModelFromSdrPage() const { return mrSdrModelFromSdrPage; }
393 protected:
394 std::unique_ptr<sdr::contact::ViewContact> CreateObjectSpecificViewContact();
395 public:
396 const sdr::contact::ViewContact& GetViewContact() const;
397 sdr::contact::ViewContact& GetViewContact();
399 // #110094# DrawContact support: Methods for handling Page changes
400 void ActionChanged();
402 private:
403 // the SdrModel this page was created with, unchanged during SdrPage lifetime
404 SdrModel& mrSdrModelFromSdrPage;
406 private:
407 sal_Int32 mnWidth; // page size
408 sal_Int32 mnHeight; // page size
409 sal_Int32 mnBorderLeft; // left page margin
410 sal_Int32 mnBorderUpper; // top page margin
411 sal_Int32 mnBorderRight; // right page margin
412 sal_Int32 mnBorderLower; // bottom page margin
414 std::unique_ptr<SdrLayerAdmin> mpLayerAdmin;
415 std::unique_ptr<SdrPageProperties> mpSdrPageProperties;
416 css::uno::Reference< css::uno::XInterface > mxUnoPage;
418 public:
419 SdrPageProperties& getSdrPageProperties();
420 const SdrPageProperties& getSdrPageProperties() const;
421 const SdrPageProperties* getCorrectSdrPageProperties() const;
423 protected:
424 // new MasterPageDescriptorVector
425 std::unique_ptr<sdr::MasterPageDescriptor> mpMasterPageDescriptor;
427 sal_uInt16 nPageNum;
429 bool mbMaster : 1; // flag if this is a MasterPage
430 bool mbInserted : 1;
431 bool mbObjectsNotPersistent : 1;
433 // #i93597#
434 bool mbPageBorderOnlyLeftRight : 1;
436 void SetUnoPage(css::uno::Reference<css::drawing::XDrawPage> const&);
437 virtual css::uno::Reference< css::uno::XInterface > createUnoPage();
439 // Copying of pages is split into two parts: construction and copying of page objects,
440 // because the copying might need access to fully initialized page. CloneSdrPage() is responsible
441 // to call lateInit() after copy-construction of a new object. Any initialization in derived
442 // classes that needs access to the page objects must be deferred to lateInit. And it must
443 // call lateInit() of its parent class.
444 void lateInit(const SdrPage& rSrcPage);
446 public:
447 explicit SdrPage(SdrModel& rModel, bool bMasterPage=false);
448 virtual ~SdrPage() override;
450 virtual SdrPage* CloneSdrPage(SdrModel& rTargetModel) const;
451 bool IsMasterPage() const { return mbMaster; }
452 void SetInserted(bool bNew = true);
453 bool IsInserted() const { return mbInserted; }
454 void SetChanged();
456 // derived from SdrObjList, returns this
457 virtual SdrPage* getSdrPageFromSdrObjList() const override;
459 // #i68775# React on PageNum changes (from Model in most cases)
460 void SetPageNum(sal_uInt16 nNew);
461 sal_uInt16 GetPageNum() const;
463 // #i93597# Allow page border definition to not be the full rectangle but to
464 // use only the left and right vertical edges (reportdesigner)
465 void setPageBorderOnlyLeftRight(bool bNew) { mbPageBorderOnlyLeftRight = bNew; }
466 bool getPageBorderOnlyLeftRight() const { return mbPageBorderOnlyLeftRight; }
468 virtual void SetSize(const Size& aSiz);
469 Size GetSize() const;
470 virtual void SetOrientation(Orientation eOri);
471 virtual Orientation GetOrientation() const;
472 sal_Int32 GetWidth() const;
473 sal_Int32 GetHeight() const;
474 virtual void SetBorder(sal_Int32 nLft, sal_Int32 nUpp, sal_Int32 nRgt, sal_Int32 Lwr);
475 virtual void SetLeftBorder(sal_Int32 nBorder);
476 virtual void SetUpperBorder(sal_Int32 nBorder);
477 virtual void SetRightBorder(sal_Int32 nBorder);
478 virtual void SetLowerBorder(sal_Int32 nBorder);
479 sal_Int32 GetLeftBorder() const;
480 sal_Int32 GetUpperBorder() const;
481 sal_Int32 GetRightBorder() const;
482 sal_Int32 GetLowerBorder() const;
484 // New MasterPage interface
485 bool TRG_HasMasterPage() const { return (nullptr != mpMasterPageDescriptor); }
486 void TRG_SetMasterPage(SdrPage& rNew);
487 void TRG_ClearMasterPage();
488 SdrPage& TRG_GetMasterPage() const;
489 const SdrLayerIDSet& TRG_GetMasterPageVisibleLayers() const;
490 void TRG_SetMasterPageVisibleLayers(const SdrLayerIDSet& rNew);
491 sdr::contact::ViewContact& TRG_GetMasterPageDescriptorViewContact() const;
493 void MakePageObjectsNamesUnique();
495 protected:
496 void TRG_ImpMasterPageRemoved(const SdrPage& rRemovedPage);
497 public:
499 /// changing the layers does not set the modified-flag!
500 const SdrLayerAdmin& GetLayerAdmin() const;
501 SdrLayerAdmin& GetLayerAdmin();
503 virtual OUString GetLayoutName() const;
505 /// for snap-to-grid in Writer, also for AlignObjects if 1 object is marked
506 /// if pRect != null, then the pages that are intersected by this Rect,
507 /// otherwise the visible pages
508 virtual const SdrPageGridFrameList* GetGridFrameList(const SdrPageView* pPV, const tools::Rectangle* pRect) const;
510 css::uno::Reference< css::uno::XInterface > const & getUnoPage();
512 virtual SfxStyleSheet* GetTextStyleSheetForObject( SdrObject* pObj ) const;
514 /** *deprecated* returns an averaged background color of this page */
515 // #i75566# GetBackgroundColor -> GetPageBackgroundColor
516 Color GetPageBackgroundColor() const;
518 /** *deprecated* returns an averaged background color of this page */
519 // #i75566# GetBackgroundColor -> GetPageBackgroundColor and bScreenDisplay hint value
520 Color GetPageBackgroundColor( SdrPageView const * pView, bool bScreenDisplay = true) const;
522 /** this method returns true if the object from the ViewObjectContact should
523 be visible on this page while rendering.
524 bEdit selects if visibility test is for an editing view or a final render,
525 like printing.
527 virtual bool checkVisibility(
528 const sdr::contact::ViewObjectContact& rOriginal,
529 const sdr::contact::DisplayInfo& rDisplayInfo,
530 bool bEdit );
534 #endif // INCLUDED_SVX_SVDPAGE_HXX
536 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */