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/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 <svx/svdtypes.hxx>
31 #include <svx/svdlayer.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>
44 namespace reportdesign
{ class OSection
; }
45 namespace sdr
{ namespace contact
{ class ViewContact
; }}
54 class SvxUnoDrawPagesAccess
;
56 enum SdrInsertReasonKind
{
58 SDRREASON_STREAMING
, /// importing document
59 SDRREASON_UNDO
, /// from Undo
60 SDRREASON_COPY
, /// something copied...
61 SDRREASON_VIEWCREATE
, /// created by User interactively
62 SDRREASON_VIEWCALL
/// via SdrView::Group(), ...
65 class SdrInsertReason
{
66 const SdrObject
* pRefObj
;
67 SdrInsertReasonKind eReason
;
69 SdrInsertReason(): pRefObj(NULL
),eReason(SDRREASON_UNKNOWN
) {}
70 SdrInsertReason(SdrInsertReasonKind eR
,const SdrObject
* pO
=NULL
): pRefObj(pO
),eReason(eR
) {}
71 void SetReferenceObject(const SdrObject
* pO
) { pRefObj
=pO
; }
72 const SdrObject
* GetReferenceObject() const { return pRefObj
; }
73 void SetReason(SdrInsertReasonKind eR
) { eReason
=eR
; }
74 SdrInsertReasonKind
GetReason() const { return eReason
; }
80 class SVX_DLLPUBLIC SdrObjList
82 SdrObjList(const SdrObjList
& rSrcList
) SAL_DELETED_FUNCTION
;
83 SdrObjList
&operator=(const SdrObjList
& rSrcList
) SAL_DELETED_FUNCTION
;
86 typedef ::std::vector
<SdrObject
*> SdrObjectContainerType
;
87 SdrObjectContainerType maList
;
90 friend class SdrObjListIter
;
91 friend class SdrEditView
;
92 SdrObjList
* pUpList
; /// parent list
93 SdrModel
* pModel
; /// model to which the list belongs (Layer,ItemPool,Storage)
94 SdrPage
* pPage
; /// Page containing the list, may be "this".
95 SdrObject
* pOwnerObj
; /// OwnerObject, if it's list of a Group object.
98 SdrObjListKind eListKind
;
99 bool bObjOrdNumsDirty
;
105 void lateInit(const SdrObjList
& rSrcList
);
108 /// simple ActionChildInserted forwarder to have it on a central place
109 static void impChildInserted(SdrObject
& rChild
);
112 SdrObjList(SdrModel
* pNewModel
, SdrPage
* pNewPage
, SdrObjList
* pNewUpList
=NULL
);
113 virtual ~SdrObjList();
115 virtual SdrObjList
* Clone() const;
117 // !!! This method is only for people who know exactly what they do !!!
119 // #110094# This should not be needed (!)
120 void SetObjOrdNumsDirty() { bObjOrdNumsDirty
=true; }
121 void CopyObjects(const SdrObjList
& rSrcList
);
122 /// clean up everything (without Undo)
124 SdrObjListKind
GetListKind() const { return eListKind
; }
125 void SetListKind(SdrObjListKind eNewKind
) { eListKind
=eNewKind
; }
126 SdrObjList
* GetUpList() const { return pUpList
; }
127 void SetUpList(SdrObjList
* pNewUpList
) { pUpList
=pNewUpList
; }
128 SdrObject
* GetOwnerObj() const { return pOwnerObj
; }
129 void SetOwnerObj(SdrObject
* pNewOwner
) { pOwnerObj
=pNewOwner
; }
130 SdrPage
* GetPage() const;
131 void SetPage(SdrPage
* pNewPage
);
132 SdrModel
* GetModel() const;
133 virtual void SetModel(SdrModel
* pNewModel
);
134 /// recalculate order numbers / ZIndex
135 void RecalcObjOrdNums();
136 bool IsObjOrdNumsDirty() const { return bObjOrdNumsDirty
; }
137 virtual void NbcInsertObject(SdrObject
* pObj
, size_t nPos
=SAL_MAX_SIZE
138 , const SdrInsertReason
* pReason
=NULL
140 virtual void InsertObject(SdrObject
* pObj
, size_t nPos
=SAL_MAX_SIZE
141 , const SdrInsertReason
* pReason
=NULL
143 /// remove from list without delete
144 virtual SdrObject
* NbcRemoveObject(size_t nObjNum
);
145 virtual SdrObject
* RemoveObject(size_t nObjNum
);
146 /// Replace existing object by different one.
147 /// Same as Remove(old)+Insert(new) but faster because the order numbers
148 /// do not have to be set dirty.
149 virtual SdrObject
* NbcReplaceObject(SdrObject
* pNewObj
, size_t nObjNum
);
150 virtual SdrObject
* ReplaceObject(SdrObject
* pNewObj
, size_t nObjNum
);
151 /// Modify ZOrder of an SdrObject
152 virtual SdrObject
* SetObjectOrdNum(size_t nOldObjNum
, size_t nNewObjNum
);
154 void SetRectsDirty();
156 const Rectangle
& GetAllObjSnapRect() const;
157 const Rectangle
& GetAllObjBoundRect() const;
159 /// reformat all text objects, e.g. when changing printer
160 void NbcReformatAllTextObjects();
161 void ReformatAllTextObjects();
163 /** #103122# reformats all edge objects that are connected to other objects */
164 void ReformatAllEdgeObjects();
166 /// convert attributes of the style to hard formatting
167 void BurnInStyleSheetAttributes();
169 size_t GetObjCount() const;
170 SdrObject
* GetObj(size_t nNum
) const;
172 /// linked page or linked group object
173 virtual bool IsReadOnly() const;
175 /// count all objects including objects in Groups
176 size_t CountAllObjects() const;
178 /** Makes the object list flat, i.e. the object list content are
181 This method travels recursively over all group objects in this
182 list, extracts the content, inserts it flat to the list and
183 removes the group object afterwards.
185 void FlattenGroups();
186 /** Ungroup the object at the given index
188 This method ungroups the content of the group object at the
189 given index, i.e. the content is put flat into the object list
190 (if the object at the given index is no group, this method is
191 a no-op). If the group itself contains group objects, the
192 operation is performed recursively, such that the content of
193 the given object contains no groups afterwards.
195 void UnGroupObj( size_t nObjNum
);
197 /** Return whether there is an explicit, user defined, object navigation
198 order. When there is one this method returns <TRUE/> and the
199 GetObjectForNavigationPosition() and
200 SdrObject::GetNavigationPosition() methods will return values
201 different from those returne by SdrObject::GetOrdNum() and
204 bool HasObjectNavigationOrder() const;
206 /** Set the navigation position of the given object to the specified
207 value. Note that this changes the navigation position for all
208 objects on or following the old or new position.
210 void SetObjectNavigationPosition (
212 const sal_uInt32 nNewNavigationPosition
);
214 /** Return the object for the given navigation position. When there is
215 a user defined navigation order, i.e. mxNavigationOrder is not NULL,
216 then that is used to look up the object. Otherwise the z-order is
217 used by looking up the object in maList.
218 @param nNavigationPosition
219 Valid values include 0 and are smaller than the number of
220 objects as returned by GetObjCount().
222 The returned pointer is NULL for invalid positions.
224 SdrObject
* GetObjectForNavigationPosition (const sal_uInt32 nNavigationPosition
) const;
226 /** Restore the navigation order to that defined by the z-order.
228 void ClearObjectNavigationOrder();
230 /** Set the navigation position of all SdrObjects to their position in
231 the mxNavigationOrder list. This method returns immediately when no
234 This method returns <TRUE/> when the navigation positions stored
235 in SdrObjects are up to date.
236 It returns <FALSE/> when the navigation positions are not valid,
237 for example because no explicit navigation order has been
238 defined, i.e. HasObjectNavigationOrder() would return <FALSE/>.
240 bool RecalcNavigationPositions();
242 /** Set the navigation order to the one defined by the given list of
245 When this is an empty reference then the navigation order is
246 reset to the z-order. The preferred way to do this, however, is
247 to call ClearObjectNavigationOrder().
248 Otherwise this list is expected to contain all the shapes in the
251 void SetNavigationOrder (const ::com::sun::star::uno::Reference
<
252 ::com::sun::star::container::XIndexAccess
>& rxOrder
);
254 void dumpAsXml(struct _xmlTextWriter
* pWriter
) const;
257 class WeakSdrObjectContainerType
;
258 /// This list, if it exists, defines the navigation order. If it does
259 /// not exist then maList defines the navigation order.
260 std::unique_ptr
<WeakSdrObjectContainerType
> mxNavigationOrder
;
262 /// This flag is <TRUE/> when the mpNavigation list has been changed but
263 /// the indices of the referenced SdrObjects still have their old values.
264 bool mbIsNavigationOrderDirty
;
266 /** Insert an SdrObject into maList. Do not modify the maList member
269 The object to insert into the object list.
270 @param nInsertPosition
271 The given object is inserted before the object at this
272 position. Valid values include 0 (the object is inserted at the
273 head of the list) and the number of objects in the list as
274 returned by GetObjCount() (the object is inserted at the end of
277 void InsertObjectIntoContainer (
279 const sal_uInt32 nInsertPosition
);
281 /** Replace an object in the object list.
283 The new object that replaces the one in the list at the
285 @param nObjectPosition
286 The object at this position in the object list is replaced by
287 the given object. Valid values include 0 and are smaller than
288 the number of objects in the list.
290 void ReplaceObjectInContainer (
292 const sal_uInt32 nObjectPosition
);
294 /** Remove an object from the object list.
295 The object list has to contain at least one element.
296 @param nObjectPosition
297 The object at this position is removed from the object list.
298 Valid values include 0 and are smaller than the number of
301 void RemoveObjectFromContainer (
302 const sal_uInt32 nObjectPosition
);
305 // Used for all methods which return a page number
306 #define SDRPAGE_NOTFOUND 0xFFFF
309 // class SdrPageGridFrame
311 /// for the snap-to-grid in Writer
312 class SdrPageGridFrame
317 SdrPageGridFrame(const Rectangle
& rPaper
): aPaper(rPaper
), aUserArea(rPaper
) {}
318 SdrPageGridFrame(const Rectangle
& rPaper
, const Rectangle
& rUser
): aPaper(rPaper
), aUserArea(rUser
) {}
319 void SetPaperRect(const Rectangle
& rPaper
) { aPaper
=rPaper
; }
320 void SetUserArea(const Rectangle
& rUser
) { aUserArea
=rUser
; }
321 const Rectangle
& GetPaperRect() const { return aPaper
; }
322 const Rectangle
& GetUserArea() const { return aUserArea
; }
325 class SVX_DLLPUBLIC SdrPageGridFrameList
{
326 std::vector
<SdrPageGridFrame
*> aList
;
328 SdrPageGridFrameList(const SdrPageGridFrameList
& rSrcList
) SAL_DELETED_FUNCTION
;
329 void operator=(const SdrPageGridFrameList
& rSrcList
) SAL_DELETED_FUNCTION
;
331 SdrPageGridFrame
* GetObject(sal_uInt16 i
) const { return aList
[i
]; }
333 SdrPageGridFrameList(): aList() {}
334 ~SdrPageGridFrameList() { Clear(); }
336 sal_uInt16
GetCount() const { return sal_uInt16(aList
.size()); }
337 void Insert(const SdrPageGridFrame
& rGF
) { aList
.push_back(new SdrPageGridFrame(rGF
)); }
338 void Insert(const SdrPageGridFrame
& rGF
, sal_uInt16 nPos
)
341 aList
.push_back(new SdrPageGridFrame(rGF
));
343 aList
.insert(aList
.begin()+nPos
,new SdrPageGridFrame(rGF
));
345 void Delete(sal_uInt16 nPos
)
347 SdrPageGridFrame
* p
= aList
[nPos
];
348 aList
.erase(aList
.begin()+nPos
);
351 void Move(sal_uInt16 nPos
, sal_uInt16 nNewPos
)
353 SdrPageGridFrame
* p
= aList
[nPos
];
354 aList
.erase(aList
.begin()+nPos
);
355 aList
.insert(aList
.begin()+nNewPos
,p
);
357 SdrPageGridFrame
& operator[](sal_uInt16 nPos
) { return *GetObject(nPos
); }
358 const SdrPageGridFrame
& operator[](sal_uInt16 nPos
) const { return *GetObject(nPos
); }
362 // class SdrPageProperties
364 class SVX_DLLPUBLIC SdrPageProperties
: public SfxListener
, public svl::StyleSheetUser
369 SfxStyleSheet
* mpStyleSheet
;
370 SfxItemSet
* mpProperties
;
373 void ImpRemoveStyleSheet();
374 void ImpAddStyleSheet(SfxStyleSheet
& rNewStyleSheet
);
376 SdrPageProperties
& operator=(const SdrPageProperties
& rCandidate
) SAL_DELETED_FUNCTION
;
379 // construct/destruct
380 SdrPageProperties(SdrPage
& rSdrPage
);
381 virtual ~SdrPageProperties();
383 // Notify(...) from baseclass SfxListener
384 virtual void Notify(SfxBroadcaster
& rBC
, const SfxHint
& rHint
) SAL_OVERRIDE
;
386 virtual bool isUsedByModel() const SAL_OVERRIDE
;
389 const SfxItemSet
& GetItemSet() const { return *mpProperties
;}
390 void PutItemSet(const SfxItemSet
& rSet
);
391 void PutItem(const SfxPoolItem
& rItem
);
392 void ClearItem(const sal_uInt16 nWhich
= 0);
395 void SetStyleSheet(SfxStyleSheet
* pStyleSheet
);
396 SfxStyleSheet
* GetStyleSheet() const { return mpStyleSheet
;}
401 A SdrPage contains exactly one SdrObjList and a description of the physical
402 page dimensions (size / margins). The latter is required to "catch" objects
403 during drag-and-drop.
404 The SdrPage allows (via SdrObjList) inserting and removing SdrObjects,
405 as well as moving them into the foreground or background.
406 Also it's possible to request and directly set the order number (ZOrder)
409 class SVX_DLLPUBLIC SdrPage
: public SdrObjList
, public tools::WeakBase
< SdrPage
>
411 SdrPage
& operator=(const SdrPage
& rSrcPage
) SAL_DELETED_FUNCTION
;
413 // start PageUser section
415 // #111111# PageUser section
416 sdr::PageUserVector maPageUsers
;
419 void AddPageUser(sdr::PageUser
& rNewUser
);
420 void RemovePageUser(sdr::PageUser
& rOldUser
);
423 // end PageUser section
426 // #110094# DrawContact section
428 sdr::contact::ViewContact
* mpViewContact
;
430 sdr::contact::ViewContact
* CreateObjectSpecificViewContact();
432 sdr::contact::ViewContact
& GetViewContact() const;
434 // #110094# DrawContact support: Methods for handling Page changes
435 void ActionChanged() const;
438 friend class SdrModel
;
439 friend class SvxUnoDrawPagesAccess
;
441 // this class uses its own UNO wrapper
442 // and thus has to set mxUnoPage (it also relies on mxUnoPage not being WeakRef)
443 friend class reportdesign::OSection
;
445 sal_Int32 nWdt
; // Seitengroesse
446 sal_Int32 nHgt
; // Seitengroesse
447 sal_Int32 nBordLft
; // Seitenrand links
448 sal_Int32 nBordUpp
; // Seitenrand oben
449 sal_Int32 nBordRgt
; // Seitenrand rechts
450 sal_Int32 nBordLwr
; // Seitenrand unten
453 SdrLayerAdmin
* pLayerAdmin
;
455 SdrPageProperties
* mpSdrPageProperties
;
456 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> mxUnoPage
;
459 SdrPageProperties
& getSdrPageProperties() { return *mpSdrPageProperties
; }
460 const SdrPageProperties
& getSdrPageProperties() const { return *mpSdrPageProperties
; }
461 const SdrPageProperties
* getCorrectSdrPageProperties() const;
464 // new MasterPageDescriptorVector
465 sdr::MasterPageDescriptor
* mpMasterPageDescriptor
;
467 SetOfByte aPrefVisiLayers
;
471 bool mbMaster
: 1; // flag if this is a MasterPage
473 bool mbObjectsNotPersistent
: 1;
476 bool mbPageBorderOnlyLeftRight
: 1;
478 void SetUnoPage(::com::sun::star::uno::Reference
<
479 ::com::sun::star::drawing::XDrawPage
> const&);
480 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> createUnoPage();
482 // Copying of pages is split into two parts: construction and copying of page objects,
483 // because the copying might need access to fully initialized page. Clone() is responsible
484 // to call lateInit() after copy-construction of a new object. Any initialization in derived
485 // classes that needs access to the page objects must be deferred to lateInit. And it must
486 // call lateInit() of its parent class.
487 SdrPage(const SdrPage
& rSrcPage
);
488 void lateInit(const SdrPage
& rSrcPage
, SdrModel
* pNewModel
= 0);
492 explicit SdrPage(SdrModel
& rNewModel
, bool bMasterPage
=false);
494 virtual SdrPage
* Clone() const SAL_OVERRIDE
;
495 virtual SdrPage
* Clone(SdrModel
* pNewModel
) const;
496 bool IsMasterPage() const { return mbMaster
; }
497 void SetInserted(bool bNew
= true);
498 bool IsInserted() const { return mbInserted
; }
501 // #i68775# React on PageNum changes (from Model in most cases)
502 void SetPageNum(sal_uInt16 nNew
);
503 sal_uInt16
GetPageNum() const;
505 // #i93597# Allow page border definition to not be the full rectangle but to
506 // use only the left and right vertical edges (reportdesigner)
507 void setPageBorderOnlyLeftRight(bool bNew
) { mbPageBorderOnlyLeftRight
= bNew
; }
508 bool getPageBorderOnlyLeftRight() const { return mbPageBorderOnlyLeftRight
; }
510 virtual void SetSize(const Size
& aSiz
);
511 Size
GetSize() const;
512 virtual void SetOrientation(Orientation eOri
);
513 virtual Orientation
GetOrientation() const;
514 sal_Int32
GetWdt() const;
515 sal_Int32
GetHgt() const;
516 virtual void SetBorder(sal_Int32 nLft
, sal_Int32 nUpp
, sal_Int32 nRgt
, sal_Int32 Lwr
);
517 virtual void SetLftBorder(sal_Int32 nBorder
);
518 virtual void SetUppBorder(sal_Int32 nBorder
);
519 virtual void SetRgtBorder(sal_Int32 nBorder
);
520 virtual void SetLwrBorder(sal_Int32 nBorder
);
521 sal_Int32
GetLftBorder() const;
522 sal_Int32
GetUppBorder() const;
523 sal_Int32
GetRgtBorder() const;
524 sal_Int32
GetLwrBorder() const;
526 virtual void SetModel(SdrModel
* pNewModel
) SAL_OVERRIDE
;
528 // New MasterPage interface
529 bool TRG_HasMasterPage() const { return (0L != mpMasterPageDescriptor
); }
530 void TRG_SetMasterPage(SdrPage
& rNew
);
531 void TRG_ClearMasterPage();
532 SdrPage
& TRG_GetMasterPage() const;
533 const SetOfByte
& TRG_GetMasterPageVisibleLayers() const;
534 void TRG_SetMasterPageVisibleLayers(const SetOfByte
& rNew
);
535 sdr::contact::ViewContact
& TRG_GetMasterPageDescriptorViewContact() const;
538 void TRG_ImpMasterPageRemoved(const SdrPage
& rRemovedPage
);
541 /// changing the layers does not set the modified-flag!
542 const SdrLayerAdmin
& GetLayerAdmin() const { return *pLayerAdmin
; }
543 SdrLayerAdmin
& GetLayerAdmin() { return *pLayerAdmin
; }
545 virtual OUString
GetLayoutName() const;
547 /// for snap-to-grid in Writer, also for AlignObjects if 1 object is marked
548 /// if pRect != null, then the pages that are intersected by this Rect,
549 /// otherwise the visible pages
550 virtual const SdrPageGridFrameList
* GetGridFrameList(const SdrPageView
* pPV
, const Rectangle
* pRect
) const;
551 bool IsObjectsNotPersistent() const { return mbObjectsNotPersistent
; }
552 void SetObjectsNotPersistent(bool b
) { mbObjectsNotPersistent
= b
; }
554 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> getUnoPage();
556 virtual SfxStyleSheet
* GetTextStyleSheetForObject( SdrObject
* pObj
) const;
558 /** *deprecated* returns an averaged background color of this page */
559 // #i75566# GetBackgroundColor -> GetPageBackgroundColor
560 Color
GetPageBackgroundColor() const;
562 /** *deprecated* returns an averaged background color of this page */
563 // #i75566# GetBackgroundColor -> GetPageBackgroundColor and bScreenDisplay hint value
564 Color
GetPageBackgroundColor( SdrPageView
* pView
, bool bScreenDisplay
= true) const;
566 /** this method returns true if the object from the ViewObjectContact should
567 be visible on this page while rendering.
568 bEdit selects if visibility test is for an editing view or a final render,
571 virtual bool checkVisibility(
572 const sdr::contact::ViewObjectContact
& rOriginal
,
573 const sdr::contact::DisplayInfo
& rDisplayInfo
,
577 void impl_setModelForLayerAdmin(SdrModel
* pNewModel
);
580 typedef tools::WeakReference
< SdrPage
> SdrPageWeakRef
;
583 // use new redirector instead of pPaintProc
585 class SVX_DLLPUBLIC StandardCheckVisisbilityRedirector
: public sdr::contact::ViewObjectContactRedirector
588 StandardCheckVisisbilityRedirector();
589 virtual ~StandardCheckVisisbilityRedirector();
591 // all default implementations just call the same methods at the original. To do something
592 // different, override the method and at least do what the method does.
593 virtual drawinglayer::primitive2d::Primitive2DSequence
createRedirectedPrimitive2DSequence(
594 const sdr::contact::ViewObjectContact
& rOriginal
,
595 const sdr::contact::DisplayInfo
& rDisplayInfo
) SAL_OVERRIDE
;
600 #endif // INCLUDED_SVX_SVDPAGE_HXX
602 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */