bump product version to 6.3.0.0.beta1
[LibreOffice.git] / include / svx / svdpage.hxx
blobd23957dcd9062ef5be30c69a7f562556b2424d62
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/bitmap.hxx>
25 #include <vcl/print.hxx>
26 #include <vcl/gdimtf.hxx>
27 #include <tools/weakbase.hxx>
28 #include <tools/contnr.hxx>
29 #include <cppuhelper/weakref.hxx>
30 #include <svl/itemset.hxx>
31 #include <svx/svdtypes.hxx>
32 #include <svx/sdrpageuser.hxx>
33 #include <svx/sdr/contact/viewobjectcontactredirector.hxx>
34 #include <svx/sdrmasterpagedescriptor.hxx>
35 #include <svx/svxdllapi.h>
36 #include <com/sun/star/container/XIndexAccess.hpp>
37 #include <com/sun/star/drawing/XDrawPage.hpp>
38 #include <svx/svdobj.hxx>
39 #include <memory>
40 #include <vector>
43 // predefines
44 namespace reportdesign { class OSection; }
45 namespace sdr { namespace contact { class ViewContact; }}
46 class SdrPage;
47 class SdrModel;
48 class SfxItemPool;
49 class SdrPageView;
50 class SdrLayerAdmin;
51 class SdrLayerIDSet;
52 class Color;
53 class SfxStyleSheet;
54 class SvxUnoDrawPagesAccess;
56 ////////////////////////////////////////////////////////////////////////////////////////////////////
58 // SdrObjList
59 // E3dObjList
60 // SdrPage -> see continuation there
62 // class SdrObjList
63 class SVX_DLLPUBLIC SdrObjList
65 friend class SdrObjListIter;
66 friend class SdrEditView;
68 private:
69 SdrObjList(const SdrObjList& rSrcList) = delete;
70 SdrObjList &operator=(const SdrObjList& rSrcList) = delete;
72 ::std::vector<SdrObject*> maList;
74 tools::Rectangle maSdrObjListOutRect;
75 tools::Rectangle maSdrObjListSnapRect;
76 bool mbObjOrdNumsDirty;
77 bool mbRectsDirty;
79 protected:
80 void RecalcRects();
82 private:
83 /// simple ActionChildInserted forwarder to have it on a central place
84 static void impChildInserted(SdrObject const & rChild);
86 // tdf#116879 Clear SdrObjList, no Undo done. Used from destructor, but also
87 // from other places. When used from destructor, suppress broadcasts
88 // to not get callbacks to evtl. derived objects already in destruction
89 // (e.g. SdrPage)
90 void impClearSdrObjList(bool bBroadcast);
92 protected:
93 // protected constructor to make clear that this class should only
94 // be used as base for derivations, not naked. See getSdrModelFromSdrObjList
95 // which is pure virtual to force this, too
96 SdrObjList();
97 virtual ~SdrObjList();
99 public:
100 // SdrModel/SdrPage access on SdrObjList level
101 virtual SdrPage* getSdrPageFromSdrObjList() const;
102 virtual SdrObject* getSdrObjectFromSdrObjList() const;
104 void CopyObjects(const SdrObjList& rSrcList);
106 // tdf#116879 clean up everything (without Undo), plus broadcasting
107 // changes. Split to this call and a private one (impClearSdrObjList)
108 // that allows cleanup without broadcasting in the destructor
109 void ClearSdrObjList();
111 /// recalculate order numbers / ZIndex
112 void RecalcObjOrdNums();
113 bool IsObjOrdNumsDirty() const { return mbObjOrdNumsDirty; }
114 virtual void NbcInsertObject(SdrObject* pObj, size_t nPos=SAL_MAX_SIZE);
115 virtual void InsertObject(SdrObject* pObj, size_t nPos=SAL_MAX_SIZE);
117 /// remove from list without delete
118 virtual SdrObject* NbcRemoveObject(size_t nObjNum);
119 virtual SdrObject* RemoveObject(size_t nObjNum);
121 /// Replace existing object by different one.
122 /// Same as Remove(old)+Insert(new) but faster because the order numbers
123 /// do not have to be set dirty.
124 virtual SdrObject* ReplaceObject(SdrObject* pNewObj, size_t nObjNum);
126 /// Modify ZOrder of an SdrObject
127 virtual SdrObject* SetObjectOrdNum(size_t nOldObjNum, size_t nNewObjNum);
129 void SetSdrObjListRectsDirty();
131 const tools::Rectangle& GetAllObjSnapRect() const;
132 const tools::Rectangle& GetAllObjBoundRect() const;
134 /// reformat all text objects, e.g. when changing printer
135 void NbcReformatAllTextObjects();
136 void ReformatAllTextObjects();
138 /** #103122# reformats all edge objects that are connected to other objects */
139 void ReformatAllEdgeObjects();
141 /// convert attributes of the style to hard formatting
142 void BurnInStyleSheetAttributes();
144 size_t GetObjCount() const;
145 SdrObject* GetObj(size_t nNum) const;
147 /// linked page or linked group object
148 virtual bool IsReadOnly() const;
150 /** Makes the object list flat, i.e. the object list content are
151 then tree leaves
153 This method travels recursively over all group objects in this
154 list, extracts the content, inserts it flat to the list and
155 removes the group object afterwards.
157 void FlattenGroups();
159 /** Ungroup the object at the given index
161 This method ungroups the content of the group object at the
162 given index, i.e. the content is put flat into the object list
163 (if the object at the given index is no group, this method is
164 a no-op). If the group itself contains group objects, the
165 operation is performed recursively, such that the content of
166 the given object contains no groups afterwards.
168 void UnGroupObj( size_t nObjNum );
170 /** Return whether there is an explicit, user defined, object navigation
171 order. When there is one this method returns <TRUE/> and the
172 GetObjectForNavigationPosition() and
173 SdrObject::GetNavigationPosition() methods will return values
174 different from those returne by SdrObject::GetOrdNum() and
175 GetObj().
177 bool HasObjectNavigationOrder() const;
179 /** Set the navigation position of the given object to the specified
180 value. Note that this changes the navigation position for all
181 objects on or following the old or new position.
183 void SetObjectNavigationPosition (
184 SdrObject& rObject,
185 const sal_uInt32 nNewNavigationPosition);
187 /** Return the object for the given navigation position. When there is
188 a user defined navigation order, i.e. mxNavigationOrder is not NULL,
189 then that is used to look up the object. Otherwise the z-order is
190 used by looking up the object in maList.
191 @param nNavigationPosition
192 Valid values include 0 and are smaller than the number of
193 objects as returned by GetObjCount().
194 @return
195 The returned pointer is NULL for invalid positions.
197 SdrObject* GetObjectForNavigationPosition (const sal_uInt32 nNavigationPosition) const;
199 /** Restore the navigation order to that defined by the z-order.
201 void ClearObjectNavigationOrder();
203 /** Set the navigation position of all SdrObjects to their position in
204 the mxNavigationOrder list. This method returns immediately when no
205 update is necessary.
206 @return
207 This method returns <TRUE/> when the navigation positions stored
208 in SdrObjects are up to date.
209 It returns <FALSE/> when the navigation positions are not valid,
210 for example because no explicit navigation order has been
211 defined, i.e. HasObjectNavigationOrder() would return <FALSE/>.
213 bool RecalcNavigationPositions();
215 /** Set the navigation order to the one defined by the given list of
216 XShape objects.
217 @param rxOrder
218 When this is an empty reference then the navigation order is
219 reset to the z-order. The preferred way to do this, however, is
220 to call ClearObjectNavigationOrder().
221 Otherwise this list is expected to contain all the shapes in the
222 called SdrObjList.
224 void SetNavigationOrder (const css::uno::Reference<
225 css::container::XIndexAccess>& rxOrder);
227 virtual void dumpAsXml(xmlTextWriterPtr pWriter) const;
229 private:
230 class WeakSdrObjectContainerType;
231 /// This list, if it exists, defines the navigation order. If it does
232 /// not exist then maList defines the navigation order.
233 std::unique_ptr<WeakSdrObjectContainerType> mxNavigationOrder;
235 /// This flag is <TRUE/> when the mpNavigation list has been changed but
236 /// the indices of the referenced SdrObjects still have their old values.
237 bool mbIsNavigationOrderDirty;
239 /** Insert an SdrObject into maList. Do not modify the maList member
240 directly.
241 @param rObject
242 The object to insert into the object list.
243 @param nInsertPosition
244 The given object is inserted before the object at this
245 position. Valid values include 0 (the object is inserted at the
246 head of the list) and the number of objects in the list as
247 returned by GetObjCount() (the object is inserted at the end of
248 the list.)
250 void InsertObjectIntoContainer (
251 SdrObject& rObject,
252 const sal_uInt32 nInsertPosition);
254 /** Replace an object in the object list.
255 @param rObject
256 The new object that replaces the one in the list at the
257 specified position.
258 @param nObjectPosition
259 The object at this position in the object list is replaced by
260 the given object. Valid values include 0 and are smaller than
261 the number of objects in the list.
263 void ReplaceObjectInContainer (
264 SdrObject& rObject,
265 const sal_uInt32 nObjectPosition);
267 /** Remove an object from the object list.
268 The object list has to contain at least one element.
269 @param nObjectPosition
270 The object at this position is removed from the object list.
271 Valid values include 0 and are smaller than the number of
272 objects in the list.
274 void RemoveObjectFromContainer (
275 const sal_uInt32 nObjectPosition);
278 // Used for all methods which return a page number
279 #define SDRPAGE_NOTFOUND 0xFFFF
281 /// for the snap-to-grid in Writer
282 class SdrPageGridFrame
284 tools::Rectangle const aPaper;
285 tools::Rectangle const aUserArea;
286 public:
287 SdrPageGridFrame(const tools::Rectangle& rPaper, const tools::Rectangle& rUser): aPaper(rPaper), aUserArea(rUser) {}
288 const tools::Rectangle& GetPaperRect() const { return aPaper; }
289 const tools::Rectangle& GetUserArea() const { return aUserArea; }
292 class SVX_DLLPUBLIC SdrPageGridFrameList final
294 std::vector<SdrPageGridFrame*> aList;
296 SdrPageGridFrameList(const SdrPageGridFrameList& rSrcList) = delete;
297 void operator=(const SdrPageGridFrameList& rSrcList) = delete;
298 SdrPageGridFrame* GetObject(sal_uInt16 i) const { return aList[i]; }
300 public:
301 SdrPageGridFrameList(): aList() {}
302 ~SdrPageGridFrameList() { Clear(); }
303 void Clear();
304 sal_uInt16 GetCount() const { return sal_uInt16(aList.size()); }
305 void Insert(const SdrPageGridFrame& rGF) { aList.push_back(new SdrPageGridFrame(rGF)); }
306 SdrPageGridFrame& operator[](sal_uInt16 nPos) { return *GetObject(nPos); }
307 const SdrPageGridFrame& operator[](sal_uInt16 nPos) const { return *GetObject(nPos); }
310 // class SdrPageProperties
311 class SVX_DLLPUBLIC SdrPageProperties : public SfxListener, public svl::StyleSheetUser
313 private:
314 // data
315 SdrPage* mpSdrPage;
316 SfxStyleSheet* mpStyleSheet;
317 SfxItemSet maProperties;
319 // internal helpers
320 void ImpRemoveStyleSheet();
321 void ImpAddStyleSheet(SfxStyleSheet& rNewStyleSheet);
323 SdrPageProperties& operator=(const SdrPageProperties& rCandidate) = delete;
325 public:
326 // construct/destruct
327 SdrPageProperties(SdrPage& rSdrPage);
328 virtual ~SdrPageProperties() override;
330 // Notify(...) from baseclass SfxListener
331 virtual void Notify(SfxBroadcaster& rBC, const SfxHint& rHint) override;
333 virtual bool isUsedByModel() const override;
335 // data read/write
336 const SfxItemSet& GetItemSet() const { return maProperties;}
337 void PutItemSet(const SfxItemSet& rSet);
338 void PutItem(const SfxPoolItem& rItem);
339 void ClearItem(const sal_uInt16 nWhich = 0);
341 // StyleSheet access
342 void SetStyleSheet(SfxStyleSheet* pStyleSheet);
343 SfxStyleSheet* GetStyleSheet() const { return mpStyleSheet;}
348 A SdrPage contains exactly one SdrObjList and a description of the physical
349 page dimensions (size / margins). The latter is required to "catch" objects
350 during drag-and-drop.
351 The SdrPage allows (via SdrObjList) inserting and removing SdrObjects,
352 as well as moving them into the foreground or background.
353 Also it's possible to request and directly set the order number (ZOrder)
354 of SdrObjects.
357 ////////////////////////////////////////////////////////////////////////////////////////////////////
359 // SdrPage
360 // DlgEdPage
361 // FmFormPage
362 // ScDrawPage
363 // SdPage
364 // SwDPage
365 // OReportPage
367 class SVX_DLLPUBLIC SdrPage : public SdrObjList, public tools::WeakBase
369 // #i9076#
370 friend class SdrModel;
371 friend class SvxUnoDrawPagesAccess;
373 // this class uses its own UNO wrapper
374 // and thus has to set mxUnoPage (it also relies on mxUnoPage not being WeakRef)
375 friend class reportdesign::OSection;
377 SdrPage& operator=(const SdrPage&) = delete;
378 SdrPage(const SdrPage&) = delete;
380 // start PageUser section
381 private:
382 // #111111# PageUser section
383 sdr::PageUserVector maPageUsers;
385 std::unique_ptr<sdr::contact::ViewContact> mpViewContact;
387 public:
388 void AddPageUser(sdr::PageUser& rNewUser);
389 void RemovePageUser(sdr::PageUser& rOldUser);
391 // SdrModel access on SdrPage level
392 SdrModel& getSdrModelFromSdrPage() const { return mrSdrModelFromSdrPage; }
394 protected:
395 std::unique_ptr<sdr::contact::ViewContact> CreateObjectSpecificViewContact();
396 public:
397 const sdr::contact::ViewContact& GetViewContact() const;
398 sdr::contact::ViewContact& GetViewContact();
400 // #110094# DrawContact support: Methods for handling Page changes
401 void ActionChanged();
403 private:
404 // the SdrModel this page was created with, unchanged during SdrPage lifetime
405 SdrModel& mrSdrModelFromSdrPage;
407 private:
408 sal_Int32 mnWidth; // page size
409 sal_Int32 mnHeight; // page size
410 sal_Int32 mnBorderLeft; // left page margin
411 sal_Int32 mnBorderUpper; // top page margin
412 sal_Int32 mnBorderRight; // right page margin
413 sal_Int32 mnBorderLower; // bottom page margin
415 std::unique_ptr<SdrLayerAdmin> mpLayerAdmin;
416 std::unique_ptr<SdrPageProperties> mpSdrPageProperties;
417 css::uno::Reference< css::uno::XInterface > mxUnoPage;
419 public:
420 SdrPageProperties& getSdrPageProperties();
421 const SdrPageProperties& getSdrPageProperties() const;
422 const SdrPageProperties* getCorrectSdrPageProperties() const;
424 protected:
425 // new MasterPageDescriptorVector
426 std::unique_ptr<sdr::MasterPageDescriptor> mpMasterPageDescriptor;
428 sal_uInt16 nPageNum;
430 bool mbMaster : 1; // flag if this is a MasterPage
431 bool mbInserted : 1;
432 bool mbObjectsNotPersistent : 1;
434 // #i93597#
435 bool mbPageBorderOnlyLeftRight : 1;
437 void SetUnoPage(css::uno::Reference<css::drawing::XDrawPage> const&);
438 virtual css::uno::Reference< css::uno::XInterface > createUnoPage();
440 // Copying of pages is split into two parts: construction and copying of page objects,
441 // because the copying might need access to fully initialized page. CloneSdrPage() is responsible
442 // to call lateInit() after copy-construction of a new object. Any initialization in derived
443 // classes that needs access to the page objects must be deferred to lateInit. And it must
444 // call lateInit() of its parent class.
445 void lateInit(const SdrPage& rSrcPage);
447 public:
448 explicit SdrPage(SdrModel& rModel, bool bMasterPage=false);
449 virtual ~SdrPage() override;
451 virtual SdrPage* CloneSdrPage(SdrModel& rTargetModel) const;
452 bool IsMasterPage() const { return mbMaster; }
453 void SetInserted(bool bNew = true);
454 bool IsInserted() const { return mbInserted; }
455 void SetChanged();
457 // derived from SdrObjList, returns this
458 virtual SdrPage* getSdrPageFromSdrObjList() const override;
460 // #i68775# React on PageNum changes (from Model in most cases)
461 void SetPageNum(sal_uInt16 nNew);
462 sal_uInt16 GetPageNum() const;
464 // #i93597# Allow page border definition to not be the full rectangle but to
465 // use only the left and right vertical edges (reportdesigner)
466 void setPageBorderOnlyLeftRight(bool bNew) { mbPageBorderOnlyLeftRight = bNew; }
467 bool getPageBorderOnlyLeftRight() const { return mbPageBorderOnlyLeftRight; }
469 virtual void SetSize(const Size& aSiz);
470 Size GetSize() const;
471 virtual void SetOrientation(Orientation eOri);
472 virtual Orientation GetOrientation() const;
473 sal_Int32 GetWidth() const;
474 sal_Int32 GetHeight() const;
475 virtual void SetBorder(sal_Int32 nLft, sal_Int32 nUpp, sal_Int32 nRgt, sal_Int32 Lwr);
476 virtual void SetLeftBorder(sal_Int32 nBorder);
477 virtual void SetUpperBorder(sal_Int32 nBorder);
478 virtual void SetRightBorder(sal_Int32 nBorder);
479 virtual void SetLowerBorder(sal_Int32 nBorder);
480 sal_Int32 GetLeftBorder() const;
481 sal_Int32 GetUpperBorder() const;
482 sal_Int32 GetRightBorder() const;
483 sal_Int32 GetLowerBorder() const;
485 // New MasterPage interface
486 bool TRG_HasMasterPage() const { return (nullptr != mpMasterPageDescriptor); }
487 void TRG_SetMasterPage(SdrPage& rNew);
488 void TRG_ClearMasterPage();
489 SdrPage& TRG_GetMasterPage() const;
490 const SdrLayerIDSet& TRG_GetMasterPageVisibleLayers() const;
491 void TRG_SetMasterPageVisibleLayers(const SdrLayerIDSet& rNew);
492 sdr::contact::ViewContact& TRG_GetMasterPageDescriptorViewContact() const;
494 protected:
495 void TRG_ImpMasterPageRemoved(const SdrPage& rRemovedPage);
496 public:
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,
524 like printing.
526 virtual bool checkVisibility(
527 const sdr::contact::ViewObjectContact& rOriginal,
528 const sdr::contact::DisplayInfo& rDisplayInfo,
529 bool bEdit );
533 #endif // INCLUDED_SVX_SVDPAGE_HXX
535 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */