tdf#151073 - enable firebird for appstore build w/o experimental mode
[LibreOffice.git] / include / svx / svdpage.hxx
blob5b6a1a434da0a03947be3c50e005541fc3d05538
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 #pragma once
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 <svx/ColorSets.hxx>
34 #include <unotools/weakref.hxx>
35 #include <memory>
36 #include <optional>
37 #include <vector>
38 #include <deque>
41 // predefines
42 namespace reportdesign { class OSection; }
43 namespace sdr::contact { class ViewContact; }
44 class SdrPage;
45 class SdrModel;
46 class SfxItemPool;
47 class SdrPageView;
48 class SdrLayerAdmin;
49 class SdrLayerIDSet;
50 class Color;
51 class SfxStyleSheet;
52 class SvxUnoDrawPagesAccess;
54 ////////////////////////////////////////////////////////////////////////////////////////////////////
56 // SdrObjList
57 // E3dObjList
58 // SdrPage -> see continuation there
60 // class SdrObjList
61 class SVXCORE_DLLPUBLIC SdrObjList
63 friend class SdrObjListIter;
64 friend class SdrEditView;
66 private:
67 SdrObjList(const SdrObjList& rSrcList) = delete;
68 SdrObjList &operator=(const SdrObjList& rSrcList) = delete;
70 protected:
71 void RecalcRects();
73 private:
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
80 // (e.g. SdrPage)
81 void impClearSdrObjList(bool bBroadcast);
83 protected:
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
87 SdrObjList();
88 virtual ~SdrObjList();
90 public:
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;
145 /// linked page or linked group object
146 virtual bool IsReadOnly() const;
148 /** Makes the object list flat, i.e. the object list content are
149 then tree leaves
151 This method travels recursively over all group objects in this
152 list, extracts the content, inserts it flat to the list and
153 removes the group object afterwards.
155 void FlattenGroups();
157 /** Ungroup the object at the given index
159 This method ungroups the content of the group object at the
160 given index, i.e. the content is put flat into the object list
161 (if the object at the given index is no group, this method is
162 a no-op). If the group itself contains group objects, the
163 operation is performed recursively, such that the content of
164 the given object contains no groups afterwards.
166 void UnGroupObj( size_t nObjNum );
168 /** Return whether there is an explicit, user defined, object navigation
169 order. When there is one this method returns <TRUE/> and the
170 GetObjectForNavigationPosition() and
171 SdrObject::GetNavigationPosition() methods will return values
172 different from those returned by SdrObject::GetOrdNum() and
173 GetObj().
175 bool HasObjectNavigationOrder() const;
177 /** Set the navigation position of the given object to the specified
178 value. Note that this changes the navigation position for all
179 objects on or following the old or new position.
181 void SetObjectNavigationPosition (
182 SdrObject& rObject,
183 const sal_uInt32 nNewNavigationPosition);
185 /** Return the object for the given navigation position. When there is
186 a user defined navigation order, i.e. mxNavigationOrder is not NULL,
187 then that is used to look up the object. Otherwise the z-order is
188 used by looking up the object in maList.
189 @param nNavigationPosition
190 Valid values include 0 and are smaller than the number of
191 objects as returned by GetObjCount().
192 @return
193 The returned pointer is NULL for invalid positions.
195 SdrObject* GetObjectForNavigationPosition (const sal_uInt32 nNavigationPosition) const;
197 /** Restore the navigation order to that defined by the z-order.
199 void ClearObjectNavigationOrder();
201 /** Set the navigation position of all SdrObjects to their position in
202 the mxNavigationOrder list. This method returns immediately when no
203 update is necessary.
204 @return
205 This method returns <TRUE/> when the navigation positions stored
206 in SdrObjects are up to date.
207 It returns <FALSE/> when the navigation positions are not valid,
208 for example because no explicit navigation order has been
209 defined, i.e. HasObjectNavigationOrder() would return <FALSE/>.
211 bool RecalcNavigationPositions();
213 /** Set the navigation order to the one defined by the given list of
214 XShape objects.
215 @param rxOrder
216 When this is an empty reference then the navigation order is
217 reset to the z-order. The preferred way to do this, however, is
218 to call ClearObjectNavigationOrder().
219 Otherwise this list is expected to contain all the shapes in the
220 called SdrObjList.
222 void SetNavigationOrder (const css::uno::Reference<
223 css::container::XIndexAccess>& rxOrder);
225 virtual void dumpAsXml(xmlTextWriterPtr pWriter) const;
227 private:
228 tools::Rectangle maSdrObjListOutRect;
229 tools::Rectangle maSdrObjListSnapRect;
230 std::deque<rtl::Reference<SdrObject>> maList;
231 /// This list, if it exists, defines the navigation order. If it does
232 /// not exist then maList defines the navigation order.
233 std::optional<std::vector<unotools::WeakReference<SdrObject>>> mxNavigationOrder;
234 bool mbObjOrdNumsDirty;
235 bool mbRectsDirty;
236 /// This flag is <TRUE/> when the mpNavigation list has been changed but
237 /// the indices of the referenced SdrObjects still have their old values.
238 bool mbIsNavigationOrderDirty;
240 /** Insert an SdrObject into maList. Do not modify the maList member
241 directly.
242 @param rObject
243 The object to insert into the object list.
244 @param nInsertPosition
245 The given object is inserted before the object at this
246 position. Valid values include 0 (the object is inserted at the
247 head of the list) and the number of objects in the list as
248 returned by GetObjCount() (the object is inserted at the end of
249 the list.)
251 void InsertObjectIntoContainer (
252 SdrObject& rObject,
253 const sal_uInt32 nInsertPosition);
255 /** Replace an object in the object list.
256 @param rObject
257 The new object that replaces the one in the list at the
258 specified position.
259 @param nObjectPosition
260 The object at this position in the object list is replaced by
261 the given object. Valid values include 0 and are smaller than
262 the number of objects in the list.
264 void ReplaceObjectInContainer (
265 SdrObject& rObject,
266 const sal_uInt32 nObjectPosition);
268 /** Remove an object from the object list.
269 The object list has to contain at least one element.
270 @param nObjectPosition
271 The object at this position is removed from the object list.
272 Valid values include 0 and are smaller than the number of
273 objects in the list.
275 void RemoveObjectFromContainer (
276 const sal_uInt32 nObjectPosition);
278 void ImplReformatAllEdgeObjects(const SdrObjList& );
281 // Used for all methods which return a page number
282 #define SDRPAGE_NOTFOUND 0xFFFF
284 /// for the snap-to-grid in Writer
285 class SdrPageGridFrame
287 tools::Rectangle aPaper;
288 tools::Rectangle aUserArea;
289 public:
290 SdrPageGridFrame(const tools::Rectangle& rPaper, const tools::Rectangle& rUser): aPaper(rPaper), aUserArea(rUser) {}
291 const tools::Rectangle& GetPaperRect() const { return aPaper; }
292 const tools::Rectangle& GetUserArea() const { return aUserArea; }
295 class SVXCORE_DLLPUBLIC SdrPageGridFrameList final
297 std::vector<SdrPageGridFrame*> aList;
299 SdrPageGridFrameList(const SdrPageGridFrameList& rSrcList) = delete;
300 void operator=(const SdrPageGridFrameList& rSrcList) = delete;
301 SdrPageGridFrame* GetObject(sal_uInt16 i) const { return aList[i]; }
303 public:
304 SdrPageGridFrameList() {}
305 ~SdrPageGridFrameList() { Clear(); }
306 void Clear();
307 sal_uInt16 GetCount() const { return sal_uInt16(aList.size()); }
308 void Insert(const SdrPageGridFrame& rGF) { aList.push_back(new SdrPageGridFrame(rGF)); }
309 SdrPageGridFrame& operator[](sal_uInt16 nPos) { return *GetObject(nPos); }
310 const SdrPageGridFrame& operator[](sal_uInt16 nPos) const { return *GetObject(nPos); }
313 // class SdrPageProperties
314 class SVXCORE_DLLPUBLIC SdrPageProperties final : public SfxListener, public svl::StyleSheetUser
316 private:
317 // data
318 SdrPage* mpSdrPage;
319 SfxStyleSheet* mpStyleSheet;
320 std::unique_ptr<svx::Theme> mpTheme;
321 SfxItemSet maProperties;
323 // internal helpers
324 void ImpRemoveStyleSheet();
325 void ImpAddStyleSheet(SfxStyleSheet& rNewStyleSheet);
327 SdrPageProperties& operator=(const SdrPageProperties& rCandidate) = delete;
329 public:
330 // construct/destruct
331 SdrPageProperties(SdrPage& rSdrPage);
332 virtual ~SdrPageProperties() override;
334 // Notify(...) from baseclass SfxListener
335 virtual void Notify(SfxBroadcaster& rBC, const SfxHint& rHint) override;
337 virtual bool isUsedByModel() const override;
339 // data read/write
340 const SfxItemSet& GetItemSet() const { return maProperties;}
341 void PutItemSet(const SfxItemSet& rSet);
342 void PutItem(const SfxPoolItem& rItem);
343 void ClearItem(const sal_uInt16 nWhich = 0);
345 // StyleSheet access
346 void SetStyleSheet(SfxStyleSheet* pStyleSheet);
347 SfxStyleSheet* GetStyleSheet() const { return mpStyleSheet;}
349 void SetTheme(std::unique_ptr<svx::Theme> pTheme);
350 svx::Theme* GetTheme();
352 void dumpAsXml(xmlTextWriterPtr pWriter) const;
357 A SdrPage contains exactly one SdrObjList and a description of the physical
358 page dimensions (size / margins). The latter is required to "catch" objects
359 during drag-and-drop.
360 The SdrPage allows (via SdrObjList) inserting and removing SdrObjects,
361 as well as moving them into the foreground or background.
362 Also it's possible to request and directly set the order number (ZOrder)
363 of SdrObjects.
366 ////////////////////////////////////////////////////////////////////////////////////////////////////
368 // SdrPage
369 // DlgEdPage
370 // FmFormPage
371 // ScDrawPage
372 // SdPage
373 // SwDPage
374 // OReportPage
376 class SVXCORE_DLLPUBLIC SdrPage : public SdrObjList, public cppu::OWeakObject
378 // #i9076#
379 friend class SdrModel;
380 friend class SvxUnoDrawPagesAccess;
382 // this class uses its own UNO wrapper
383 // and thus has to set mxUnoPage (it also relies on mxUnoPage not being WeakRef)
384 friend class reportdesign::OSection;
386 SdrPage& operator=(const SdrPage&) = delete;
387 SdrPage(const SdrPage&) = delete;
389 // start PageUser section
390 private:
391 // #111111# PageUser section
392 sdr::PageUserVector maPageUsers;
394 std::unique_ptr<sdr::contact::ViewContact> mpViewContact;
396 public:
397 void AddPageUser(sdr::PageUser& rNewUser);
398 void RemovePageUser(sdr::PageUser& rOldUser);
400 // SdrModel access on SdrPage level
401 SdrModel& getSdrModelFromSdrPage() const { return mrSdrModelFromSdrPage; }
403 protected:
404 std::unique_ptr<sdr::contact::ViewContact> CreateObjectSpecificViewContact();
405 public:
406 const sdr::contact::ViewContact& GetViewContact() const;
407 sdr::contact::ViewContact& GetViewContact();
409 // #110094# DrawContact support: Methods for handling Page changes
410 void ActionChanged();
412 private:
413 // the SdrModel this page was created with, unchanged during SdrPage lifetime
414 SdrModel& mrSdrModelFromSdrPage;
416 private:
417 tools::Long mnWidth; // page size
418 tools::Long mnHeight; // page size
419 sal_Int32 mnBorderLeft; // left page margin
420 sal_Int32 mnBorderUpper; // top page margin
421 sal_Int32 mnBorderRight; // right page margin
422 sal_Int32 mnBorderLower; // bottom page margin
423 bool mbBackgroundFullSize = false; ///< Background object to represent the whole page.
425 std::unique_ptr<SdrLayerAdmin> mpLayerAdmin;
426 std::unique_ptr<SdrPageProperties> mpSdrPageProperties;
427 css::uno::Reference< css::uno::XInterface > mxUnoPage;
429 public:
430 SdrPageProperties& getSdrPageProperties();
431 const SdrPageProperties& getSdrPageProperties() const;
432 const SdrPageProperties* getCorrectSdrPageProperties() const;
434 protected:
435 // new MasterPageDescriptorVector
436 std::unique_ptr<sdr::MasterPageDescriptor> mpMasterPageDescriptor;
438 sal_uInt16 nPageNum;
440 bool mbMaster : 1; // flag if this is a MasterPage
441 bool mbInserted : 1;
442 bool mbObjectsNotPersistent : 1;
444 // #i93597#
445 bool mbPageBorderOnlyLeftRight : 1;
447 void SetUnoPage(css::uno::Reference<css::drawing::XDrawPage> const&);
448 virtual css::uno::Reference< css::uno::XInterface > createUnoPage();
450 // Copying of pages is split into two parts: construction and copying of page objects,
451 // because the copying might need access to fully initialized page. CloneSdrPage() is responsible
452 // to call lateInit() after copy-construction of a new object. Any initialization in derived
453 // classes that needs access to the page objects must be deferred to lateInit. And it must
454 // call lateInit() of its parent class.
455 void lateInit(const SdrPage& rSrcPage);
457 public:
458 explicit SdrPage(SdrModel& rModel, bool bMasterPage=false);
459 virtual ~SdrPage() override;
461 virtual rtl::Reference<SdrPage> CloneSdrPage(SdrModel& rTargetModel) const;
462 bool IsMasterPage() const { return mbMaster; }
463 void SetInserted(bool bNew = true);
464 bool IsInserted() const { return mbInserted; }
465 void SetChanged();
467 // derived from SdrObjList, returns this
468 virtual SdrPage* getSdrPageFromSdrObjList() const override;
470 // #i68775# React on PageNum changes (from Model in most cases)
471 void SetPageNum(sal_uInt16 nNew);
472 sal_uInt16 GetPageNum() const;
474 // #i93597# Allow page border definition to not be the full rectangle but to
475 // use only the left and right vertical edges (reportdesigner)
476 void setPageBorderOnlyLeftRight(bool bNew) { mbPageBorderOnlyLeftRight = bNew; }
477 bool getPageBorderOnlyLeftRight() const { return mbPageBorderOnlyLeftRight; }
479 virtual void SetSize(const Size& aSiz);
480 Size GetSize() const;
481 virtual void SetOrientation(Orientation eOri);
482 virtual Orientation GetOrientation() const;
483 tools::Long GetWidth() const;
484 tools::Long GetHeight() const;
485 virtual void SetBorder(sal_Int32 nLft, sal_Int32 nUpp, sal_Int32 nRgt, sal_Int32 Lwr);
486 virtual void SetLeftBorder(sal_Int32 nBorder);
487 virtual void SetUpperBorder(sal_Int32 nBorder);
488 virtual void SetRightBorder(sal_Int32 nBorder);
489 virtual void SetLowerBorder(sal_Int32 nBorder);
490 sal_Int32 GetLeftBorder() const;
491 sal_Int32 GetUpperBorder() const;
492 sal_Int32 GetRightBorder() const;
493 sal_Int32 GetLowerBorder() const;
494 void SetBackgroundFullSize(bool bIn);
495 bool IsBackgroundFullSize() const;
497 // New MasterPage interface
498 bool TRG_HasMasterPage() const { return (nullptr != mpMasterPageDescriptor); }
499 void TRG_SetMasterPage(SdrPage& rNew);
500 void TRG_ClearMasterPage();
501 SdrPage& TRG_GetMasterPage() const;
502 const SdrLayerIDSet& TRG_GetMasterPageVisibleLayers() const;
503 void TRG_SetMasterPageVisibleLayers(const SdrLayerIDSet& rNew);
504 sdr::contact::ViewContact& TRG_GetMasterPageDescriptorViewContact() const;
506 void MakePageObjectsNamesUnique();
508 protected:
509 void TRG_ImpMasterPageRemoved(const SdrPage& rRemovedPage);
510 public:
512 /// changing the layers does not set the modified-flag!
513 const SdrLayerAdmin& GetLayerAdmin() const;
514 SdrLayerAdmin& GetLayerAdmin();
516 virtual OUString GetLayoutName() const;
518 /// for snap-to-grid in Writer, also for AlignObjects if 1 object is marked
519 /// if pRect != null, then the pages that are intersected by this Rect,
520 /// otherwise the visible pages
521 virtual const SdrPageGridFrameList* GetGridFrameList(const SdrPageView* pPV, const tools::Rectangle* pRect) const;
523 css::uno::Reference< css::uno::XInterface > const & getUnoPage();
525 virtual SfxStyleSheet* GetTextStyleSheetForObject( SdrObject* pObj ) const;
527 /** *deprecated* returns an averaged background color of this page */
528 // #i75566# GetBackgroundColor -> GetPageBackgroundColor
529 Color GetPageBackgroundColor() const;
531 /** *deprecated* returns an averaged background color of this page */
532 // #i75566# GetBackgroundColor -> GetPageBackgroundColor and bScreenDisplay hint value
533 Color GetPageBackgroundColor( SdrPageView const * pView, bool bScreenDisplay = true) const;
535 /** this method returns true if the object from the ViewObjectContact should
536 be visible on this page while rendering.
537 bEdit selects if visibility test is for an editing view or a final render,
538 like printing.
540 virtual bool checkVisibility(
541 const sdr::contact::ViewObjectContact& rOriginal,
542 const sdr::contact::DisplayInfo& rDisplayInfo,
543 bool bEdit );
545 void dumpAsXml(xmlTextWriterPtr pWriter) const override;
548 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */