LibreOffice Module svx (master)  1
svdpage.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #pragma once
21 
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>
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 <memory>
35 #include <optional>
36 #include <vector>
37 #include <deque>
38 
39 
40 // predefines
41 namespace reportdesign { class OSection; }
42 namespace sdr::contact { class ViewContact; }
43 class SdrPage;
44 class SdrModel;
45 class SfxItemPool;
46 class SdrPageView;
47 class SdrLayerAdmin;
48 class SdrLayerIDSet;
49 class Color;
50 class SfxStyleSheet;
52 
54 //
55 // SdrObjList
56 // E3dObjList
57 // SdrPage -> see continuation there
58 
59 // class SdrObjList
61 {
62 friend class SdrObjListIter;
63 friend class SdrEditView;
64 
65 private:
66  SdrObjList(const SdrObjList& rSrcList) = delete;
67  SdrObjList &operator=(const SdrObjList& rSrcList) = delete;
68 
69 protected:
70  void RecalcRects();
71 
72 private:
74  static void impChildInserted(SdrObject const & rChild);
75 
76  // tdf#116879 Clear SdrObjList, no Undo done. Used from destructor, but also
77  // from other places. When used from destructor, suppress broadcasts
78  // to not get callbacks to evtl. derived objects already in destruction
79  // (e.g. SdrPage)
80  void impClearSdrObjList(bool bBroadcast);
81 
82 protected:
83  // protected constructor to make clear that this class should only
84  // be used as base for derivations, not naked. See getSdrModelFromSdrObjList
85  // which is pure virtual to force this, too
86  SdrObjList();
87  virtual ~SdrObjList();
88 
89 public:
90  // SdrModel/SdrPage access on SdrObjList level
91  virtual SdrPage* getSdrPageFromSdrObjList() const;
92  virtual SdrObject* getSdrObjectFromSdrObjList() const;
93 
94  void CopyObjects(const SdrObjList& rSrcList);
95 
96  // tdf#116879 clean up everything (without Undo), plus broadcasting
97  // changes. Split to this call and a private one (impClearSdrObjList)
98  // that allows cleanup without broadcasting in the destructor
99  void ClearSdrObjList();
100 
102  void RecalcObjOrdNums();
103  bool IsObjOrdNumsDirty() const { return mbObjOrdNumsDirty; }
104  virtual void NbcInsertObject(SdrObject* pObj, size_t nPos=SAL_MAX_SIZE);
105  virtual void InsertObject(SdrObject* pObj, size_t nPos=SAL_MAX_SIZE);
106  void sort( std::vector<sal_Int32>& sortOrder );
107 
108  void InsertObjectThenMakeNameUnique(SdrObject* pObj);
109  void InsertObjectThenMakeNameUnique(SdrObject* pObj, std::unordered_set<rtl::OUString>& rNameSet, size_t nPos=SAL_MAX_SIZE);
110 
112  virtual SdrObject* NbcRemoveObject(size_t nObjNum);
113  virtual SdrObject* RemoveObject(size_t nObjNum);
114 
118  virtual SdrObject* ReplaceObject(SdrObject* pNewObj, size_t nObjNum);
119 
121  virtual SdrObject* SetObjectOrdNum(size_t nOldObjNum, size_t nNewObjNum);
122 
124  void SetExistingObjectOrdNum(SdrObject* pExistingObj, size_t nNewObjNum);
125 
126  void SetSdrObjListRectsDirty();
127 
128  const tools::Rectangle& GetAllObjSnapRect() const;
129  const tools::Rectangle& GetAllObjBoundRect() const;
130 
132  void NbcReformatAllTextObjects();
133  void ReformatAllTextObjects();
134 
136  void ReformatAllEdgeObjects();
137 
139  void BurnInStyleSheetAttributes();
140 
141  size_t GetObjCount() const;
142  SdrObject* GetObj(size_t nNum) const;
143 
145  virtual bool IsReadOnly() const;
146 
154  void FlattenGroups();
155 
165  void UnGroupObj( size_t nObjNum );
166 
174  bool HasObjectNavigationOrder() const;
175 
180  void SetObjectNavigationPosition (
181  SdrObject& rObject,
182  const sal_uInt32 nNewNavigationPosition);
183 
194  SdrObject* GetObjectForNavigationPosition (const sal_uInt32 nNavigationPosition) const;
195 
198  void ClearObjectNavigationOrder();
199 
210  bool RecalcNavigationPositions();
211 
221  void SetNavigationOrder (const css::uno::Reference<
222  css::container::XIndexAccess>& rxOrder);
223 
224  virtual void dumpAsXml(xmlTextWriterPtr pWriter) const;
225 
226 private:
229  std::deque<SdrObject*> maList;
232  std::optional<std::vector<tools::WeakReference<SdrObject>>> mxNavigationOrder;
238 
250  void InsertObjectIntoContainer (
251  SdrObject& rObject,
252  const sal_uInt32 nInsertPosition);
253 
263  void ReplaceObjectInContainer (
264  SdrObject& rObject,
265  const sal_uInt32 nObjectPosition);
266 
274  void RemoveObjectFromContainer (
275  const sal_uInt32 nObjectPosition);
276 };
277 
278 // Used for all methods which return a page number
279 #define SDRPAGE_NOTFOUND 0xFFFF
280 
283 {
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; }
290 };
291 
293 {
294  std::vector<SdrPageGridFrame*> aList;
295 
296  SdrPageGridFrameList(const SdrPageGridFrameList& rSrcList) = delete;
297  void operator=(const SdrPageGridFrameList& rSrcList) = delete;
298  SdrPageGridFrame* GetObject(sal_uInt16 i) const { return aList[i]; }
299 
300 public:
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); }
308 };
309 
310 // class SdrPageProperties
312 {
313 private:
314  // data
317  std::unique_ptr<svx::Theme> mpTheme;
319 
320  // internal helpers
321  void ImpRemoveStyleSheet();
322  void ImpAddStyleSheet(SfxStyleSheet& rNewStyleSheet);
323 
324  SdrPageProperties& operator=(const SdrPageProperties& rCandidate) = delete;
325 
326 public:
327  // construct/destruct
328  SdrPageProperties(SdrPage& rSdrPage);
329  virtual ~SdrPageProperties() override;
330 
331  // Notify(...) from baseclass SfxListener
332  virtual void Notify(SfxBroadcaster& rBC, const SfxHint& rHint) override;
333 
334  virtual bool isUsedByModel() const override;
335 
336  // data read/write
337  const SfxItemSet& GetItemSet() const { return maProperties;}
338  void PutItemSet(const SfxItemSet& rSet);
339  void PutItem(const SfxPoolItem& rItem);
340  void ClearItem(const sal_uInt16 nWhich = 0);
341 
342  // StyleSheet access
343  void SetStyleSheet(SfxStyleSheet* pStyleSheet);
344  SfxStyleSheet* GetStyleSheet() const { return mpStyleSheet;}
345 
346  void SetTheme(std::unique_ptr<svx::Theme> pTheme);
347  svx::Theme* GetTheme();
348 
349  void dumpAsXml(xmlTextWriterPtr pWriter) const;
350 };
351 
352 
363 //
365 // SdrPage
366 // DlgEdPage
367 // FmFormPage
368 // ScDrawPage
369 // SdPage
370 // SwDPage
371 // OReportPage
372 
374 {
375  // #i9076#
376  friend class SdrModel;
377  friend class SvxUnoDrawPagesAccess;
378 
379  // this class uses its own UNO wrapper
380  // and thus has to set mxUnoPage (it also relies on mxUnoPage not being WeakRef)
382 
383  SdrPage& operator=(const SdrPage&) = delete;
384  SdrPage(const SdrPage&) = delete;
385 
386  // start PageUser section
387 private:
388  // #111111# PageUser section
390 
391  std::unique_ptr<sdr::contact::ViewContact> mpViewContact;
392 
393 public:
394  void AddPageUser(sdr::PageUser& rNewUser);
395  void RemovePageUser(sdr::PageUser& rOldUser);
396 
397  // SdrModel access on SdrPage level
398  SdrModel& getSdrModelFromSdrPage() const { return mrSdrModelFromSdrPage; }
399 
400 protected:
401  std::unique_ptr<sdr::contact::ViewContact> CreateObjectSpecificViewContact();
402 public:
403  const sdr::contact::ViewContact& GetViewContact() const;
404  sdr::contact::ViewContact& GetViewContact();
405 
406  // #110094# DrawContact support: Methods for handling Page changes
407  void ActionChanged();
408 
409 private:
410  // the SdrModel this page was created with, unchanged during SdrPage lifetime
412 
413 private:
414  tools::Long mnWidth; // page size
415  tools::Long mnHeight; // page size
416  sal_Int32 mnBorderLeft; // left page margin
417  sal_Int32 mnBorderUpper; // top page margin
418  sal_Int32 mnBorderRight; // right page margin
419  sal_Int32 mnBorderLower; // bottom page margin
420  bool mbBackgroundFullSize = false;
421 
422  std::unique_ptr<SdrLayerAdmin> mpLayerAdmin;
423  std::unique_ptr<SdrPageProperties> mpSdrPageProperties;
424  css::uno::Reference< css::uno::XInterface > mxUnoPage;
425 
426 public:
427  SdrPageProperties& getSdrPageProperties();
428  const SdrPageProperties& getSdrPageProperties() const;
429  const SdrPageProperties* getCorrectSdrPageProperties() const;
430 
431 protected:
432  // new MasterPageDescriptorVector
433  std::unique_ptr<sdr::MasterPageDescriptor> mpMasterPageDescriptor;
434 
435  sal_uInt16 nPageNum;
436 
437  bool mbMaster : 1; // flag if this is a MasterPage
438  bool mbInserted : 1;
439  bool mbObjectsNotPersistent : 1;
440 
441  // #i93597#
442  bool mbPageBorderOnlyLeftRight : 1;
443 
444  void SetUnoPage(css::uno::Reference<css::drawing::XDrawPage> const&);
445  virtual css::uno::Reference< css::uno::XInterface > createUnoPage();
446 
447  // Copying of pages is split into two parts: construction and copying of page objects,
448  // because the copying might need access to fully initialized page. CloneSdrPage() is responsible
449  // to call lateInit() after copy-construction of a new object. Any initialization in derived
450  // classes that needs access to the page objects must be deferred to lateInit. And it must
451  // call lateInit() of its parent class.
452  void lateInit(const SdrPage& rSrcPage);
453 
454 public:
455  explicit SdrPage(SdrModel& rModel, bool bMasterPage=false);
456  virtual ~SdrPage() override;
457 
458  virtual rtl::Reference<SdrPage> CloneSdrPage(SdrModel& rTargetModel) const;
459  bool IsMasterPage() const { return mbMaster; }
460  void SetInserted(bool bNew = true);
461  bool IsInserted() const { return mbInserted; }
462  void SetChanged();
463 
464  // derived from SdrObjList, returns this
465  virtual SdrPage* getSdrPageFromSdrObjList() const override;
466 
467  // #i68775# React on PageNum changes (from Model in most cases)
468  void SetPageNum(sal_uInt16 nNew);
469  sal_uInt16 GetPageNum() const;
470 
471  // #i93597# Allow page border definition to not be the full rectangle but to
472  // use only the left and right vertical edges (reportdesigner)
473  void setPageBorderOnlyLeftRight(bool bNew) { mbPageBorderOnlyLeftRight = bNew; }
474  bool getPageBorderOnlyLeftRight() const { return mbPageBorderOnlyLeftRight; }
475 
476  virtual void SetSize(const Size& aSiz);
477  Size GetSize() const;
478  virtual void SetOrientation(Orientation eOri);
479  virtual Orientation GetOrientation() const;
480  tools::Long GetWidth() const;
481  tools::Long GetHeight() const;
482  virtual void SetBorder(sal_Int32 nLft, sal_Int32 nUpp, sal_Int32 nRgt, sal_Int32 Lwr);
483  virtual void SetLeftBorder(sal_Int32 nBorder);
484  virtual void SetUpperBorder(sal_Int32 nBorder);
485  virtual void SetRightBorder(sal_Int32 nBorder);
486  virtual void SetLowerBorder(sal_Int32 nBorder);
487  sal_Int32 GetLeftBorder() const;
488  sal_Int32 GetUpperBorder() const;
489  sal_Int32 GetRightBorder() const;
490  sal_Int32 GetLowerBorder() const;
491  void SetBackgroundFullSize(bool bIn);
492  bool IsBackgroundFullSize() const;
493 
494  // New MasterPage interface
495  bool TRG_HasMasterPage() const { return (nullptr != mpMasterPageDescriptor); }
496  void TRG_SetMasterPage(SdrPage& rNew);
497  void TRG_ClearMasterPage();
498  SdrPage& TRG_GetMasterPage() const;
499  const SdrLayerIDSet& TRG_GetMasterPageVisibleLayers() const;
500  void TRG_SetMasterPageVisibleLayers(const SdrLayerIDSet& rNew);
501  sdr::contact::ViewContact& TRG_GetMasterPageDescriptorViewContact() const;
502 
503  void MakePageObjectsNamesUnique();
504 
505 protected:
506  void TRG_ImpMasterPageRemoved(const SdrPage& rRemovedPage);
507 public:
508 
510  const SdrLayerAdmin& GetLayerAdmin() const;
511  SdrLayerAdmin& GetLayerAdmin();
512 
513  virtual OUString GetLayoutName() const;
514 
518  virtual const SdrPageGridFrameList* GetGridFrameList(const SdrPageView* pPV, const tools::Rectangle* pRect) const;
519 
520  css::uno::Reference< css::uno::XInterface > const & getUnoPage();
521 
522  virtual SfxStyleSheet* GetTextStyleSheetForObject( SdrObject* pObj ) const;
523 
525  // #i75566# GetBackgroundColor -> GetPageBackgroundColor
526  Color GetPageBackgroundColor() const;
527 
529  // #i75566# GetBackgroundColor -> GetPageBackgroundColor and bScreenDisplay hint value
530  Color GetPageBackgroundColor( SdrPageView const * pView, bool bScreenDisplay = true) const;
531 
537  virtual bool checkVisibility(
538  const sdr::contact::ViewObjectContact& rOriginal,
539  const sdr::contact::DisplayInfo& rDisplayInfo,
540  bool bEdit );
541 
542  void dumpAsXml(xmlTextWriterPtr pWriter) const override;
543 };
544 
545 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< sdr::MasterPageDescriptor > mpMasterPageDescriptor
Definition: svdpage.hxx:433
const SdrPageGridFrame & operator[](sal_uInt16 nPos) const
Definition: svdpage.hxx:307
::std::vector< PageUser * > PageUserVector
Definition: sdrpageuser.hxx:46
std::unique_ptr< svx::Theme > mpTheme
Definition: svdpage.hxx:317
tools::Rectangle maSdrObjListOutRect
Definition: svdpage.hxx:227
sdr::PageUserVector maPageUsers
Definition: svdpage.hxx:389
struct _xmlTextWriter * xmlTextWriterPtr
for the snap-to-grid in Writer
Definition: svdpage.hxx:282
bool mbObjOrdNumsDirty
Definition: svdpage.hxx:233
sal_Int32 mnBorderRight
Definition: svdpage.hxx:418
long Long
tools::Long mnHeight
Definition: svdpage.hxx:415
const SfxListener & operator=(const SfxListener &)=delete
bool mbRectsDirty
Definition: svdpage.hxx:234
const tools::Rectangle & GetUserArea() const
Definition: svdpage.hxx:289
std::optional< std::vector< tools::WeakReference< SdrObject > > > mxNavigationOrder
This list, if it exists, defines the navigation order.
Definition: svdpage.hxx:232
bool lateInit
const SfxBroadcaster & operator=(const SfxBroadcaster &)=delete
const tools::Rectangle & GetPaperRect() const
Definition: svdpage.hxx:288
virtual bool isUsedByModel() const =0
SfxStyleSheet * mpStyleSheet
Definition: svdpage.hxx:316
tools::Rectangle aUserArea
Definition: svdpage.hxx:285
bool IsObjOrdNumsDirty() const
Definition: svdpage.hxx:103
SdrModel & mrSdrModelFromSdrPage
Definition: svdpage.hxx:411
std::deque< SdrObject * > maList
Definition: svdpage.hxx:229
constexpr OUStringLiteral IsReadOnly(u"IsReadOnly")
css::uno::Reference< css::uno::XInterface > mxUnoPage
Definition: svdpage.hxx:424
SdrPageGridFrame & operator[](sal_uInt16 nPos)
Definition: svdpage.hxx:306
sal_Int32 mnBorderLeft
Definition: svdpage.hxx:416
sal_Int32 mnBorderUpper
Definition: svdpage.hxx:417
SdrPageGridFrame(const tools::Rectangle &rPaper, const tools::Rectangle &rUser)
Definition: svdpage.hxx:287
SdrObjList & operator=(const SdrObjList &rSrcList)=delete
std::vector< SdrPageGridFrame * > aList
Definition: svdpage.hxx:294
Orientation
std::unique_ptr< SdrLayerAdmin > mpLayerAdmin
Definition: svdpage.hxx:422
void Insert(const SdrPageGridFrame &rGF)
Definition: svdpage.hxx:305
SdrPage * mpSdrPage
Definition: svdpage.hxx:315
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: svdpage.cxx:1099
tools::Rectangle aPaper
Definition: svdpage.hxx:284
virtual css::uno::Reference< css::embed::XEmbeddedObject > GetObject() override
bool IsMasterPage() const
Definition: svdpage.hxx:459
const SfxItemSet & GetItemSet() const
Definition: svdpage.hxx:337
bool TRG_HasMasterPage() const
Definition: svdpage.hxx:495
Abstract DrawObject.
Definition: svdobj.hxx:259
void Clear(EHistoryType eHistory)
sal_uInt16 GetCount() const
Definition: svdpage.hxx:304
void setPageBorderOnlyLeftRight(bool bNew)
Definition: svdpage.hxx:473
SdrPageGridFrame * GetObject(sal_uInt16 i) const
Definition: svdpage.hxx:298
sal_Int32 mnBorderLower
Definition: svdpage.hxx:419
SdrModel & getSdrModelFromSdrPage() const
Definition: svdpage.hxx:398
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint)
A named theme has a named color set.
Definition: ColorSets.hxx:73
bool IsInserted() const
Definition: svdpage.hxx:461
SfxStyleSheet * GetStyleSheet() const
Definition: svdpage.hxx:344
std::unique_ptr< sdr::contact::ViewContact > mpViewContact
Definition: svdpage.hxx:391
#define SVXCORE_DLLPUBLIC
Definition: svxdllapi.h:35
virtual SdrPage * getSdrPageFromSdrObjList() const
Definition: svdpage.cxx:117
bool getPageBorderOnlyLeftRight() const
Definition: svdpage.hxx:474
bool mbIsNavigationOrderDirty
This flag is when the mpNavigation list has been changed but the indices of the referenced Sdr...
Definition: svdpage.hxx:237
SfxItemSet maProperties
Definition: svdpage.hxx:318
A SdrPage contains exactly one SdrObjList and a description of the physical page dimensions (size / m...
Definition: svdpage.hxx:373
std::unique_ptr< SdrPageProperties > mpSdrPageProperties
Definition: svdpage.hxx:423
tools::Rectangle maSdrObjListSnapRect
Definition: svdpage.hxx:228
tools::Long mnWidth
Definition: svdpage.hxx:414
sal_uInt16 nPageNum
Definition: svdpage.hxx:435