update credits
[LibreOffice.git] / svx / source / svdraw / svdpage.cxx
blob58943d2e30b7dc743b6626764649bf491c8b7547
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 #include <cassert>
22 #include <svx/svdpage.hxx>
24 // HACK
25 #include <sot/storage.hxx>
26 #include <comphelper/classids.hxx>
27 #include <svx/svdview.hxx>
28 #include <string.h>
29 #include <vcl/svapp.hxx>
31 #include <tools/diagnose_ex.h>
32 #include <tools/helpers.hxx>
34 #include <svx/svdetc.hxx>
35 #include <svx/svdobj.hxx>
36 #include <svx/svdogrp.hxx>
37 #include <svx/svdograf.hxx> // for SwapInAll()
38 #include <svx/svdoedge.hxx> // for copying the connectors
39 #include <svx/svdoole2.hxx> // special case OLE at SdrExchangeFormat
40 #include "svx/svditer.hxx"
41 #include <svx/svdmodel.hxx>
42 #include <svx/svdlayer.hxx>
43 #include <svx/svdotext.hxx>
44 #include <svx/svdpagv.hxx>
45 #include <svx/svdundo.hxx>
46 #include <svx/fmglob.hxx>
47 #include <svx/polysc3d.hxx>
49 #include <svx/fmdpage.hxx>
51 #include <sfx2/objsh.hxx>
52 #include <svx/sdr/contact/viewcontactofsdrpage.hxx>
53 #include <svx/sdr/contact/viewobjectcontact.hxx>
54 #include <svx/sdr/contact/displayinfo.hxx>
55 #include <algorithm>
56 #include <svl/smplhint.hxx>
57 #include <rtl/strbuf.hxx>
59 using namespace ::com::sun::star;
61 class SdrObjList::WeakSdrObjectContainerType
62 : public ::std::vector<SdrObjectWeakRef>
64 public:
65 WeakSdrObjectContainerType (const sal_Int32 nInitialSize)
66 : ::std::vector<SdrObjectWeakRef>(nInitialSize) {};
71 static const sal_Int32 InitialObjectContainerCapacity (64);
72 DBG_NAME(SdrObjList)
74 TYPEINIT0(SdrObjList);
76 SdrObjList::SdrObjList(SdrModel* pNewModel, SdrPage* pNewPage, SdrObjList* pNewUpList):
77 maList(),
78 mpNavigationOrder(),
79 mbIsNavigationOrderDirty(false)
81 DBG_CTOR(SdrObjList,NULL);
82 maList.reserve(InitialObjectContainerCapacity);
83 pModel=pNewModel;
84 pPage=pNewPage;
85 pUpList=pNewUpList;
86 bObjOrdNumsDirty=sal_False;
87 bRectsDirty=sal_False;
88 pOwnerObj=NULL;
89 eListKind=SDROBJLIST_UNKNOWN;
92 SdrObjList::SdrObjList(const SdrObjList& rSrcList):
93 maList(),
94 mpNavigationOrder(),
95 mbIsNavigationOrderDirty(false)
97 DBG_CTOR(SdrObjList,NULL);
98 maList.reserve(InitialObjectContainerCapacity);
99 pModel=NULL;
100 pPage=NULL;
101 pUpList=NULL;
102 bObjOrdNumsDirty=sal_False;
103 bRectsDirty=sal_False;
104 pOwnerObj=NULL;
105 eListKind=SDROBJLIST_UNKNOWN;
106 *this=rSrcList;
109 SdrObjList::~SdrObjList()
111 DBG_DTOR(SdrObjList,NULL);
113 // To avoid that the Clear() method will broadcast changes when in destruction
114 // which would call virtual methos (not allowed in destructor), the model is set
115 // to NULL here.
116 pModel = 0L;
118 Clear(); // delete contents of container
121 void SdrObjList::operator=(const SdrObjList& rSrcList)
123 Clear();
124 eListKind=rSrcList.eListKind;
125 CopyObjects(rSrcList);
128 void SdrObjList::CopyObjects(const SdrObjList& rSrcList)
130 Clear();
131 bObjOrdNumsDirty=sal_False;
132 bRectsDirty =sal_False;
133 sal_uIntPtr nCloneErrCnt=0;
134 sal_uIntPtr nAnz=rSrcList.GetObjCount();
135 SdrInsertReason aReason(SDRREASON_COPY);
136 sal_uIntPtr no;
137 for (no=0; no<nAnz; no++) {
138 SdrObject* pSO=rSrcList.GetObj(no);
140 SdrObject* pDO = pSO->Clone();
142 if (pDO!=NULL) {
143 pDO->SetModel(pModel);
144 pDO->SetPage(pPage);
145 NbcInsertObject(pDO,CONTAINER_APPEND,&aReason);
146 } else {
147 nCloneErrCnt++;
151 // and now for the Connectors
152 // The new objects would be shown in the rSrcList
153 // and then the object connections are made.
154 // Similar implementation are setup as the following:
155 // void SdrObjList::CopyObjects(const SdrObjList& rSrcList)
156 // SdrModel* SdrExchangeView::GetMarkedObjModel() const
157 // BOOL SdrExchangeView::Paste(const SdrModel& rMod,...)
158 // void SdrEditView::CopyMarked()
159 if (nCloneErrCnt==0) {
160 for (no=0; no<nAnz; no++) {
161 const SdrObject* pSrcOb=rSrcList.GetObj(no);
162 SdrEdgeObj* pSrcEdge=PTR_CAST(SdrEdgeObj,pSrcOb);
163 if (pSrcEdge!=NULL) {
164 SdrObject* pSrcNode1=pSrcEdge->GetConnectedNode(sal_True);
165 SdrObject* pSrcNode2=pSrcEdge->GetConnectedNode(sal_False);
166 if (pSrcNode1!=NULL && pSrcNode1->GetObjList()!=pSrcEdge->GetObjList()) pSrcNode1=NULL; // can't do this
167 if (pSrcNode2!=NULL && pSrcNode2->GetObjList()!=pSrcEdge->GetObjList()) pSrcNode2=NULL; // across all lists (yet)
168 if (pSrcNode1!=NULL || pSrcNode2!=NULL) {
169 SdrObject* pEdgeObjTmp=GetObj(no);
170 SdrEdgeObj* pDstEdge=PTR_CAST(SdrEdgeObj,pEdgeObjTmp);
171 if (pDstEdge!=NULL) {
172 if (pSrcNode1!=NULL) {
173 sal_uIntPtr nDstNode1=pSrcNode1->GetOrdNum();
174 SdrObject* pDstNode1=GetObj(nDstNode1);
175 if (pDstNode1!=NULL) { // else we get an error!
176 pDstEdge->ConnectToNode(sal_True,pDstNode1);
177 } else {
178 OSL_FAIL("SdrObjList::operator=(): pDstNode1==NULL!");
181 if (pSrcNode2!=NULL) {
182 sal_uIntPtr nDstNode2=pSrcNode2->GetOrdNum();
183 SdrObject* pDstNode2=GetObj(nDstNode2);
184 if (pDstNode2!=NULL) { // else the node was probably not selected
185 pDstEdge->ConnectToNode(sal_False,pDstNode2);
186 } else {
187 OSL_FAIL("SdrObjList::operator=(): pDstNode2==NULL!");
190 } else {
191 OSL_FAIL("SdrObjList::operator=(): pDstEdge==NULL!");
196 } else {
197 #ifdef DBG_UTIL
198 OStringBuffer aStr(RTL_CONSTASCII_STRINGPARAM(
199 "SdrObjList::operator=(): Error when cloning "));
201 if(nCloneErrCnt == 1)
203 aStr.append(RTL_CONSTASCII_STRINGPARAM("a drawing object."));
205 else
207 aStr.append(static_cast<sal_Int32>(nCloneErrCnt));
208 aStr.append(RTL_CONSTASCII_STRINGPARAM(" drawing objects."));
211 aStr.append(RTL_CONSTASCII_STRINGPARAM(
212 " Not copying connectors."));
214 OSL_FAIL(aStr.getStr());
215 #endif
219 void SdrObjList::Clear()
221 bool bObjectsRemoved(false);
223 while( ! maList.empty())
225 // remove last object from list
226 SdrObject* pObj = maList.back();
227 RemoveObjectFromContainer(maList.size()-1);
229 // flushViewObjectContacts() is done since SdrObject::Free is not guaranteed
230 // to delete the object and thus refresh visualisations
231 pObj->GetViewContact().flushViewObjectContacts(true);
233 bObjectsRemoved = true;
235 // sent remove hint (after removal, see RemoveObject())
236 if(pModel)
238 SdrHint aHint(*pObj);
239 aHint.SetKind(HINT_OBJREMOVED);
240 aHint.SetPage(pPage);
241 pModel->Broadcast(aHint);
244 // delete the object itself
245 SdrObject::Free( pObj );
248 if(pModel && bObjectsRemoved)
250 pModel->SetChanged();
254 SdrPage* SdrObjList::GetPage() const
256 return pPage;
259 void SdrObjList::SetPage(SdrPage* pNewPage)
261 if (pPage!=pNewPage) {
262 pPage=pNewPage;
263 sal_uIntPtr nAnz=GetObjCount();
264 for (sal_uIntPtr no=0; no<nAnz; no++) {
265 SdrObject* pObj=GetObj(no);
266 pObj->SetPage(pPage);
271 SdrModel* SdrObjList::GetModel() const
273 return pModel;
276 void SdrObjList::SetModel(SdrModel* pNewModel)
278 if (pModel!=pNewModel) {
279 pModel=pNewModel;
280 sal_uIntPtr nAnz=GetObjCount();
281 for (sal_uIntPtr i=0; i<nAnz; i++) {
282 SdrObject* pObj=GetObj(i);
283 pObj->SetModel(pModel);
288 void SdrObjList::RecalcObjOrdNums()
290 sal_uIntPtr nAnz=GetObjCount();
291 for (sal_uIntPtr no=0; no<nAnz; no++) {
292 SdrObject* pObj=GetObj(no);
293 pObj->SetOrdNum(no);
295 bObjOrdNumsDirty=sal_False;
298 void SdrObjList::RecalcRects()
300 aOutRect=Rectangle();
301 aSnapRect=aOutRect;
302 sal_uIntPtr nAnz=GetObjCount();
303 sal_uIntPtr i;
304 for (i=0; i<nAnz; i++) {
305 SdrObject* pObj=GetObj(i);
306 if (i==0) {
307 aOutRect=pObj->GetCurrentBoundRect();
308 aSnapRect=pObj->GetSnapRect();
309 } else {
310 aOutRect.Union(pObj->GetCurrentBoundRect());
311 aSnapRect.Union(pObj->GetSnapRect());
316 void SdrObjList::SetRectsDirty()
318 bRectsDirty=sal_True;
319 if (pUpList!=NULL) pUpList->SetRectsDirty();
322 void SdrObjList::impChildInserted(SdrObject& rChild) const
324 sdr::contact::ViewContact* pParent = rChild.GetViewContact().GetParentContact();
326 if(pParent)
328 pParent->ActionChildInserted(rChild.GetViewContact());
332 void SdrObjList::NbcInsertObject(SdrObject* pObj, sal_uIntPtr nPos, const SdrInsertReason* /*pReason*/)
334 DBG_ASSERT(pObj!=NULL,"SdrObjList::NbcInsertObject(NULL)");
335 if (pObj!=NULL) {
336 DBG_ASSERT(!pObj->IsInserted(),"ZObjekt already has the status Inserted.");
337 sal_uIntPtr nAnz=GetObjCount();
338 if (nPos>nAnz) nPos=nAnz;
339 InsertObjectIntoContainer(*pObj,nPos);
341 if (nPos<nAnz) bObjOrdNumsDirty=sal_True;
342 pObj->SetOrdNum(nPos);
343 pObj->SetObjList(this);
344 pObj->SetPage(pPage);
346 // Inform the parent about change to allow invalidations at
347 // evtl. existing parent visualisations
348 impChildInserted(*pObj);
350 if (!bRectsDirty) {
351 aOutRect.Union(pObj->GetCurrentBoundRect());
352 aSnapRect.Union(pObj->GetSnapRect());
354 pObj->SetInserted(sal_True); // calls the UserCall (among others)
358 void SdrObjList::InsertObject(SdrObject* pObj, sal_uIntPtr nPos, const SdrInsertReason* pReason)
360 DBG_ASSERT(pObj!=NULL,"SdrObjList::InsertObject(NULL)");
362 if(pObj)
364 // if anchor is used, reset it before grouping
365 if(GetOwnerObj())
367 const Point& rAnchorPos = pObj->GetAnchorPos();
368 if(rAnchorPos.X() || rAnchorPos.Y())
369 pObj->NbcSetAnchorPos(Point());
372 // do insert to new group
373 NbcInsertObject(pObj, nPos, pReason);
375 // In case the object is inserted into a group and doesn't overlap with
376 // the group's other members, it needs an own repaint.
377 if(pOwnerObj)
379 // only repaint here
380 pOwnerObj->ActionChanged();
383 if(pModel)
385 // TODO: We need a different broadcast here!
386 // Repaint from object number ... (heads-up: GroupObj)
387 if(pObj->GetPage())
389 SdrHint aHint(*pObj);
391 aHint.SetKind(HINT_OBJINSERTED);
392 pModel->Broadcast(aHint);
395 pModel->SetChanged();
400 SdrObject* SdrObjList::NbcRemoveObject(sal_uIntPtr nObjNum)
402 if (nObjNum >= maList.size())
404 OSL_ASSERT(nObjNum<maList.size());
405 return NULL;
408 sal_uIntPtr nAnz=GetObjCount();
409 SdrObject* pObj=maList[nObjNum];
410 RemoveObjectFromContainer(nObjNum);
412 DBG_ASSERT(pObj!=NULL,"Could not find object to remove.");
413 if (pObj!=NULL) {
414 // flushViewObjectContacts() clears the VOC's and those invalidate
415 pObj->GetViewContact().flushViewObjectContacts(true);
417 DBG_ASSERT(pObj->IsInserted(),"ZObjekt does not have the status Inserted.");
418 pObj->SetInserted(sal_False); // Ruft u.a. den UserCall
419 pObj->SetObjList(NULL);
420 pObj->SetPage(NULL);
421 if (!bObjOrdNumsDirty) { // optimizing for the case that the last object has to be removed
422 if (nObjNum!=sal_uIntPtr(nAnz-1)) {
423 bObjOrdNumsDirty=sal_True;
426 SetRectsDirty();
428 return pObj;
431 SdrObject* SdrObjList::RemoveObject(sal_uIntPtr nObjNum)
433 if (nObjNum >= maList.size())
435 OSL_ASSERT(nObjNum<maList.size());
436 return NULL;
439 sal_uIntPtr nAnz=GetObjCount();
440 SdrObject* pObj=maList[nObjNum];
441 RemoveObjectFromContainer(nObjNum);
443 DBG_ASSERT(pObj!=NULL,"Object to remove not found.");
444 if(pObj)
446 // flushViewObjectContacts() clears the VOC's and those invalidate
447 pObj->GetViewContact().flushViewObjectContacts(true);
449 DBG_ASSERT(pObj->IsInserted(),"ZObjekt does not have the status Inserted.");
450 if (pModel!=NULL) {
451 // TODO: We need a different broadcast here.
452 if (pObj->GetPage()!=NULL) {
453 SdrHint aHint(*pObj);
454 aHint.SetKind(HINT_OBJREMOVED);
455 pModel->Broadcast(aHint);
457 pModel->SetChanged();
459 pObj->SetInserted(sal_False); // calls, among other things, the UserCall
460 pObj->SetObjList(NULL);
461 pObj->SetPage(NULL);
462 if (!bObjOrdNumsDirty) { // optimization for the case that the last object is removed
463 if (nObjNum!=sal_uIntPtr(nAnz-1)) {
464 bObjOrdNumsDirty=sal_True;
467 SetRectsDirty();
469 if(pOwnerObj && !GetObjCount())
471 // empty group created; it needs to be repainted since it's
472 // visualization changes
473 pOwnerObj->ActionChanged();
476 return pObj;
479 SdrObject* SdrObjList::NbcReplaceObject(SdrObject* pNewObj, sal_uIntPtr nObjNum)
481 if (nObjNum >= maList.size() || pNewObj == NULL)
483 OSL_ASSERT(nObjNum<maList.size());
484 OSL_ASSERT(pNewObj!=NULL);
485 return NULL;
488 SdrObject* pObj=maList[nObjNum];
489 DBG_ASSERT(pObj!=NULL,"SdrObjList::ReplaceObject: Could not find object to remove.");
490 if (pObj!=NULL) {
491 DBG_ASSERT(pObj->IsInserted(),"SdrObjList::ReplaceObject: ZObjekt does not have status Inserted.");
492 pObj->SetInserted(sal_False);
493 pObj->SetObjList(NULL);
494 pObj->SetPage(NULL);
495 ReplaceObjectInContainer(*pNewObj,nObjNum);
497 // flushViewObjectContacts() clears the VOC's and those invalidate
498 pObj->GetViewContact().flushViewObjectContacts(true);
500 pNewObj->SetOrdNum(nObjNum);
501 pNewObj->SetObjList(this);
502 pNewObj->SetPage(pPage);
504 // Inform the parent about change to allow invalidations at
505 // evtl. existing parent visualisations
506 impChildInserted(*pNewObj);
508 pNewObj->SetInserted(sal_True);
509 SetRectsDirty();
511 return pObj;
514 SdrObject* SdrObjList::ReplaceObject(SdrObject* pNewObj, sal_uIntPtr nObjNum)
516 if (nObjNum >= maList.size())
518 OSL_ASSERT(nObjNum<maList.size());
519 return NULL;
521 if (pNewObj == NULL)
523 OSL_ASSERT(pNewObj!=NULL);
524 return NULL;
527 SdrObject* pObj=maList[nObjNum];
528 DBG_ASSERT(pObj!=NULL,"SdrObjList::ReplaceObject: Could not find object to remove.");
529 if (pObj!=NULL) {
530 DBG_ASSERT(pObj->IsInserted(),"SdrObjList::ReplaceObject: ZObjekt does not have status Inserted.");
531 if (pModel!=NULL) {
532 // TODO: We need a different broadcast here.
533 if (pObj->GetPage()!=NULL) {
534 SdrHint aHint(*pObj);
535 aHint.SetKind(HINT_OBJREMOVED);
536 pModel->Broadcast(aHint);
539 pObj->SetInserted(sal_False);
540 pObj->SetObjList(NULL);
541 pObj->SetPage(NULL);
542 ReplaceObjectInContainer(*pNewObj,nObjNum);
544 // flushViewObjectContacts() clears the VOC's and those invalidate
545 pObj->GetViewContact().flushViewObjectContacts(true);
547 pNewObj->SetOrdNum(nObjNum);
548 pNewObj->SetObjList(this);
549 pNewObj->SetPage(pPage);
551 // Inform the parent about change to allow invalidations at
552 // evtl. existing parent visualisations
553 impChildInserted(*pNewObj);
555 pNewObj->SetInserted(sal_True);
556 if (pModel!=NULL) {
557 // TODO: We need a different broadcast here.
558 if (pNewObj->GetPage()!=NULL) {
559 SdrHint aHint(*pNewObj);
560 aHint.SetKind(HINT_OBJINSERTED);
561 pModel->Broadcast(aHint);
563 pModel->SetChanged();
565 SetRectsDirty();
567 return pObj;
570 SdrObject* SdrObjList::NbcSetObjectOrdNum(sal_uIntPtr nOldObjNum, sal_uIntPtr nNewObjNum)
572 if (nOldObjNum >= maList.size() || nNewObjNum >= maList.size())
574 OSL_ASSERT(nOldObjNum<maList.size());
575 OSL_ASSERT(nNewObjNum<maList.size());
576 return NULL;
579 SdrObject* pObj=maList[nOldObjNum];
580 if (nOldObjNum==nNewObjNum) return pObj;
581 DBG_ASSERT(pObj!=NULL,"SdrObjList::NbcSetObjectOrdNum: Object not found.");
582 if (pObj!=NULL) {
583 DBG_ASSERT(pObj->IsInserted(),"SdrObjList::NbcSetObjectOrdNum: ZObjekt does not have status Inserted.");
584 RemoveObjectFromContainer(nOldObjNum);
586 InsertObjectIntoContainer(*pObj,nNewObjNum);
588 // No need to delete visualisation data since same object
589 // gets inserted again. Also a single ActionChanged is enough
590 pObj->ActionChanged();
592 pObj->SetOrdNum(nNewObjNum);
593 bObjOrdNumsDirty=sal_True;
595 return pObj;
598 SdrObject* SdrObjList::SetObjectOrdNum(sal_uIntPtr nOldObjNum, sal_uIntPtr nNewObjNum)
600 if (nOldObjNum >= maList.size() || nNewObjNum >= maList.size())
602 OSL_ASSERT(nOldObjNum<maList.size());
603 OSL_ASSERT(nNewObjNum<maList.size());
604 return NULL;
607 SdrObject* pObj=maList[nOldObjNum];
608 if (nOldObjNum==nNewObjNum) return pObj;
609 DBG_ASSERT(pObj!=NULL,"SdrObjList::SetObjectOrdNum: Object not found.");
610 if (pObj!=NULL) {
611 DBG_ASSERT(pObj->IsInserted(),"SdrObjList::SetObjectOrdNum: ZObjekt does not have status Inserted.");
612 RemoveObjectFromContainer(nOldObjNum);
613 InsertObjectIntoContainer(*pObj,nNewObjNum);
615 // No need to delete visualisation data since same object
616 // gets inserted again. Also a single ActionChanged is enough
617 pObj->ActionChanged();
619 pObj->SetOrdNum(nNewObjNum);
620 bObjOrdNumsDirty=sal_True;
621 if (pModel!=NULL)
623 // TODO: We need a different broadcast here.
624 if (pObj->GetPage()!=NULL) pModel->Broadcast(SdrHint(*pObj));
625 pModel->SetChanged();
628 return pObj;
631 const Rectangle& SdrObjList::GetAllObjSnapRect() const
633 if (bRectsDirty) {
634 ((SdrObjList*)this)->RecalcRects();
635 ((SdrObjList*)this)->bRectsDirty=sal_False;
637 return aSnapRect;
640 const Rectangle& SdrObjList::GetAllObjBoundRect() const
642 // #i106183# for deep group hierarchies like in chart2, the invalidates
643 // through the hierarchy are not correct; use a 2nd hint for the needed
644 // recalculation. Future versions will have no bool flag at all, but
645 // just aOutRect in empty state to represent an invalid state, thus
646 // it's a step in the right direction.
647 if (bRectsDirty || aOutRect.IsEmpty())
649 ((SdrObjList*)this)->RecalcRects();
650 ((SdrObjList*)this)->bRectsDirty=sal_False;
652 return aOutRect;
655 void SdrObjList::NbcReformatAllTextObjects()
657 sal_uIntPtr nAnz=GetObjCount();
658 sal_uIntPtr nNum=0;
660 while (nNum<nAnz)
662 SdrObject* pObj = GetObj(nNum);
664 pObj->NbcReformatText();
665 nAnz=GetObjCount(); // ReformatText may delete an object
666 nNum++;
671 void SdrObjList::ReformatAllTextObjects()
673 NbcReformatAllTextObjects();
676 /** steps over all available objects and reformats all
677 edge objects that are connected to other objects so that
678 they may reposition themselves.
680 void SdrObjList::ReformatAllEdgeObjects()
682 // #i120437# go over whole hierarchy, not only over object level null (seen from grouping)
683 SdrObjListIter aIter(*this, IM_DEEPNOGROUPS);
685 while(aIter.IsMore())
687 SdrEdgeObj* pSdrEdgeObj = dynamic_cast< SdrEdgeObj* >(aIter.Next());
689 if(pSdrEdgeObj)
691 pSdrEdgeObj->Reformat();
696 void SdrObjList::BurnInStyleSheetAttributes()
698 for(sal_uInt32 a(0L); a < GetObjCount(); a++)
700 GetObj(a)->BurnInStyleSheetAttributes();
704 sal_uIntPtr SdrObjList::GetObjCount() const
706 return maList.size();
712 SdrObject* SdrObjList::GetObj(sal_uIntPtr nNum) const
714 if (nNum >= maList.size())
716 OSL_ASSERT(nNum<maList.size());
717 return NULL;
719 else
720 return maList[nNum];
726 bool SdrObjList::IsReadOnly() const
728 bool bRet = false;
729 if (pPage!=NULL && pPage!=this) bRet=pPage->IsReadOnly();
730 return bRet;
733 sal_uIntPtr SdrObjList::CountAllObjects() const
735 sal_uIntPtr nCnt=GetObjCount();
736 sal_uIntPtr nAnz=nCnt;
737 for (sal_uInt16 nNum=0; nNum<nAnz; nNum++) {
738 SdrObjList* pSubOL=GetObj(nNum)->GetSubList();
739 if (pSubOL!=NULL) {
740 nCnt+=pSubOL->CountAllObjects();
743 return nCnt;
746 void SdrObjList::ForceSwapInObjects() const
748 sal_uIntPtr nObjAnz=GetObjCount();
749 for (sal_uIntPtr nObjNum=nObjAnz; nObjNum>0;) {
750 SdrObject* pObj=GetObj(--nObjNum);
751 SdrGrafObj* pGrafObj=PTR_CAST(SdrGrafObj,pObj);
752 if (pGrafObj!=NULL) {
753 pGrafObj->ForceSwapIn();
755 SdrObjList* pOL=pObj->GetSubList();
756 if (pOL!=NULL) {
757 pOL->ForceSwapInObjects();
762 void SdrObjList::ForceSwapOutObjects() const
764 sal_uIntPtr nObjAnz=GetObjCount();
765 for (sal_uIntPtr nObjNum=nObjAnz; nObjNum>0;) {
766 SdrObject* pObj=GetObj(--nObjNum);
767 SdrGrafObj* pGrafObj=PTR_CAST(SdrGrafObj,pObj);
768 if (pGrafObj!=NULL) {
769 pGrafObj->ForceSwapOut();
771 SdrObjList* pOL=pObj->GetSubList();
772 if (pOL!=NULL) {
773 pOL->ForceSwapOutObjects();
778 void SdrObjList::FlattenGroups()
780 sal_Int32 nObj = GetObjCount();
781 sal_Int32 i;
782 for( i=nObj-1; i>=0; --i)
783 UnGroupObj(i);
786 void SdrObjList::UnGroupObj( sal_uIntPtr nObjNum )
788 // if the given object is no group, this method is a noop
789 SdrObject* pUngroupObj = GetObj( nObjNum );
790 if( pUngroupObj )
792 SdrObjList* pSrcLst = pUngroupObj->GetSubList();
793 if( pUngroupObj->ISA( SdrObjGroup ) && pSrcLst )
795 SdrObjGroup* pUngroupGroup = static_cast< SdrObjGroup* > (pUngroupObj);
797 // ungroup recursively (has to be head recursion,
798 // otherwise our indices will get trashed when doing it in
799 // the loop)
800 pSrcLst->FlattenGroups();
802 // the position at which we insert the members of rUngroupGroup
803 sal_Int32 nInsertPos( pUngroupGroup->GetOrdNum() );
805 SdrObject* pObj;
806 sal_Int32 i, nAnz = pSrcLst->GetObjCount();
807 for( i=0; i<nAnz; ++i )
809 pObj = pSrcLst->RemoveObject(0);
810 SdrInsertReason aReason(SDRREASON_VIEWCALL, pUngroupGroup);
811 InsertObject(pObj, nInsertPos, &aReason);
812 ++nInsertPos;
815 RemoveObject(nInsertPos);
818 #ifdef DBG_UTIL
819 else
820 OSL_FAIL("SdrObjList::UnGroupObj: object index invalid");
821 #endif
827 bool SdrObjList::HasObjectNavigationOrder (void) const
829 return mpNavigationOrder.get() != NULL;
835 void SdrObjList::SetObjectNavigationPosition (
836 SdrObject& rObject,
837 const sal_uInt32 nNewPosition)
839 // When the navigation order container has not yet been created then
840 // create one now. It is initialized with the z-order taken from
841 // maList.
842 if (mpNavigationOrder.get() == NULL)
844 mpNavigationOrder.reset(new WeakSdrObjectContainerType(maList.size()));
845 ::std::copy(
846 maList.begin(),
847 maList.end(),
848 mpNavigationOrder->begin());
850 OSL_ASSERT(mpNavigationOrder.get()!=NULL);
851 OSL_ASSERT( mpNavigationOrder->size() == maList.size());
853 SdrObjectWeakRef aReference (&rObject);
855 // Look up the object whose navigation position is to be changed.
856 WeakSdrObjectContainerType::iterator iObject (::std::find(
857 mpNavigationOrder->begin(),
858 mpNavigationOrder->end(),
859 aReference));
860 if (iObject == mpNavigationOrder->end())
862 // The given object is not a member of the navigation order.
863 return;
866 // Move the object to its new position.
867 const sal_uInt32 nOldPosition = ::std::distance(mpNavigationOrder->begin(), iObject);
868 if (nOldPosition != nNewPosition)
870 mpNavigationOrder->erase(iObject);
871 sal_uInt32 nInsertPosition (nNewPosition);
872 // Adapt insertion position for the just erased object.
873 if (nNewPosition >= nOldPosition)
874 nInsertPosition -= 1;
875 if (nInsertPosition >= mpNavigationOrder->size())
876 mpNavigationOrder->push_back(aReference);
877 else
878 mpNavigationOrder->insert(mpNavigationOrder->begin()+nInsertPosition, aReference);
880 mbIsNavigationOrderDirty = true;
882 // The navigation order is written out to file so mark the model as modified.
883 if (pModel != NULL)
884 pModel->SetChanged();
891 SdrObject* SdrObjList::GetObjectForNavigationPosition (const sal_uInt32 nNavigationPosition) const
893 if (HasObjectNavigationOrder())
895 // There is a user defined navigation order. Make sure the object
896 // index is correct and look up the object in mpNavigationOrder.
897 if (nNavigationPosition >= mpNavigationOrder->size())
899 OSL_ASSERT(nNavigationPosition < mpNavigationOrder->size());
901 else
902 return (*mpNavigationOrder)[nNavigationPosition].get();
904 else
906 // There is no user defined navigation order. Use the z-order
907 // instead.
908 if (nNavigationPosition >= maList.size())
910 OSL_ASSERT(nNavigationPosition < maList.size());
912 else
913 return maList[nNavigationPosition];
915 return NULL;
921 void SdrObjList::ClearObjectNavigationOrder (void)
923 mpNavigationOrder.reset();
924 mbIsNavigationOrderDirty = true;
930 bool SdrObjList::RecalcNavigationPositions (void)
932 if (mbIsNavigationOrderDirty)
934 if (mpNavigationOrder.get() != NULL)
936 mbIsNavigationOrderDirty = false;
938 WeakSdrObjectContainerType::iterator iObject;
939 WeakSdrObjectContainerType::const_iterator iEnd (mpNavigationOrder->end());
940 sal_uInt32 nIndex (0);
941 for (iObject=mpNavigationOrder->begin(); iObject!=iEnd; ++iObject,++nIndex)
942 (*iObject)->SetNavigationPosition(nIndex);
946 return mpNavigationOrder.get() != NULL;
952 void SdrObjList::SetNavigationOrder (const uno::Reference<container::XIndexAccess>& rxOrder)
954 if (rxOrder.is())
956 const sal_Int32 nCount = rxOrder->getCount();
957 if ((sal_uInt32)nCount != maList.size())
958 return;
960 if (mpNavigationOrder.get() == NULL)
961 mpNavigationOrder.reset(new WeakSdrObjectContainerType(nCount));
963 for (sal_Int32 nIndex=0; nIndex<nCount; ++nIndex)
965 uno::Reference<uno::XInterface> xShape (rxOrder->getByIndex(nIndex), uno::UNO_QUERY);
966 SdrObject* pObject = SdrObject::getSdrObjectFromXShape(xShape);
967 if (pObject == NULL)
968 break;
969 (*mpNavigationOrder)[nIndex] = pObject;
972 mbIsNavigationOrderDirty = true;
974 else
975 ClearObjectNavigationOrder();
981 void SdrObjList::InsertObjectIntoContainer (
982 SdrObject& rObject,
983 const sal_uInt32 nInsertPosition)
985 OSL_ASSERT(nInsertPosition<=maList.size());
987 // Update the navigation positions.
988 if (HasObjectNavigationOrder())
990 // The new object does not have a user defined position so append it
991 // to the list.
992 rObject.SetNavigationPosition(mpNavigationOrder->size());
993 mpNavigationOrder->push_back(&rObject);
996 // Insert object into object list. Because the insert() method requires
997 // a valid iterator as insertion position, we have to use push_back() to
998 // insert at the end of the list.
999 if (nInsertPosition >= maList.size())
1000 maList.push_back(&rObject);
1001 else
1002 maList.insert(maList.begin()+nInsertPosition, &rObject);
1003 bObjOrdNumsDirty=sal_True;
1009 void SdrObjList::ReplaceObjectInContainer (
1010 SdrObject& rNewObject,
1011 const sal_uInt32 nObjectPosition)
1013 if (nObjectPosition >= maList.size())
1015 OSL_ASSERT(nObjectPosition<maList.size());
1016 return;
1019 // Update the navigation positions.
1020 if (HasObjectNavigationOrder())
1022 // A user defined position of the object that is to be replaced is
1023 // not transferred to the new object so erase the former and append
1024 // the later object from/to the navigation order.
1025 OSL_ASSERT(nObjectPosition < maList.size());
1026 SdrObjectWeakRef aReference (maList[nObjectPosition]);
1027 WeakSdrObjectContainerType::iterator iObject (::std::find(
1028 mpNavigationOrder->begin(),
1029 mpNavigationOrder->end(),
1030 aReference));
1031 if (iObject != mpNavigationOrder->end())
1032 mpNavigationOrder->erase(iObject);
1034 mpNavigationOrder->push_back(&rNewObject);
1036 mbIsNavigationOrderDirty = true;
1039 maList[nObjectPosition] = &rNewObject;
1040 bObjOrdNumsDirty=sal_True;
1046 void SdrObjList::RemoveObjectFromContainer (
1047 const sal_uInt32 nObjectPosition)
1049 if (nObjectPosition >= maList.size())
1051 OSL_ASSERT(nObjectPosition<maList.size());
1052 return;
1055 // Update the navigation positions.
1056 if (HasObjectNavigationOrder())
1058 SdrObjectWeakRef aReference (maList[nObjectPosition]);
1059 WeakSdrObjectContainerType::iterator iObject (::std::find(
1060 mpNavigationOrder->begin(),
1061 mpNavigationOrder->end(),
1062 aReference));
1063 if (iObject != mpNavigationOrder->end())
1064 mpNavigationOrder->erase(iObject);
1065 mbIsNavigationOrderDirty = true;
1068 maList.erase(maList.begin()+nObjectPosition);
1069 bObjOrdNumsDirty=sal_True;
1075 ////////////////////////////////////////////////////////////////////////////////////////////////////
1077 void SdrPageGridFrameList::Clear()
1079 sal_uInt16 nAnz=GetCount();
1080 for (sal_uInt16 i=0; i<nAnz; i++) {
1081 delete GetObject(i);
1083 aList.clear();
1086 //////////////////////////////////////////////////////////////////////////////
1087 // PageUser section
1089 void SdrPage::AddPageUser(sdr::PageUser& rNewUser)
1091 maPageUsers.push_back(&rNewUser);
1094 void SdrPage::RemovePageUser(sdr::PageUser& rOldUser)
1096 const ::sdr::PageUserVector::iterator aFindResult = ::std::find(maPageUsers.begin(), maPageUsers.end(), &rOldUser);
1097 if(aFindResult != maPageUsers.end())
1099 maPageUsers.erase(aFindResult);
1103 //////////////////////////////////////////////////////////////////////////////
1104 // DrawContact section
1106 sdr::contact::ViewContact* SdrPage::CreateObjectSpecificViewContact()
1108 return new sdr::contact::ViewContactOfSdrPage(*this);
1111 sdr::contact::ViewContact& SdrPage::GetViewContact() const
1113 if(!mpViewContact)
1115 const_cast< SdrPage* >(this)->mpViewContact =
1116 const_cast< SdrPage* >(this)->CreateObjectSpecificViewContact();
1119 return *mpViewContact;
1122 ////////////////////////////////////////////////////////////////////////////////////////////////////
1124 void SdrPageProperties::ImpRemoveStyleSheet()
1126 if(mpStyleSheet)
1128 EndListening(*mpStyleSheet);
1129 mpProperties->SetParent(0);
1130 mpStyleSheet = 0;
1134 void SdrPageProperties::ImpAddStyleSheet(SfxStyleSheet& rNewStyleSheet)
1136 if(mpStyleSheet != &rNewStyleSheet)
1138 ImpRemoveStyleSheet();
1139 mpStyleSheet = &rNewStyleSheet;
1140 StartListening(rNewStyleSheet);
1141 mpProperties->SetParent(&rNewStyleSheet.GetItemSet());
1145 void ImpPageChange(SdrPage& rSdrPage)
1147 rSdrPage.ActionChanged();
1149 if(rSdrPage.GetModel())
1151 rSdrPage.GetModel()->SetChanged(true);
1152 SdrHint aHint(HINT_PAGEORDERCHG);
1153 aHint.SetPage(&rSdrPage);
1154 rSdrPage.GetModel()->Broadcast(aHint);
1158 SdrPageProperties::SdrPageProperties(SdrPage& rSdrPage)
1159 : SfxListener(),
1160 mpSdrPage(&rSdrPage),
1161 mpStyleSheet(0),
1162 mpProperties(new SfxItemSet(mpSdrPage->GetModel()->GetItemPool(), XATTR_FILL_FIRST, XATTR_FILL_LAST))
1164 if(!rSdrPage.IsMasterPage())
1166 mpProperties->Put(XFillStyleItem(XFILL_NONE));
1170 SdrPageProperties::~SdrPageProperties()
1172 ImpRemoveStyleSheet();
1173 delete mpProperties;
1176 void SdrPageProperties::Notify(SfxBroadcaster& /*rBC*/, const SfxHint& rHint)
1178 const SfxSimpleHint* pSimpleHint = dynamic_cast< const SfxSimpleHint* >(&rHint);
1180 if(pSimpleHint)
1182 switch(pSimpleHint->GetId())
1184 case SFX_HINT_DATACHANGED :
1186 // notify change, broadcast
1187 ImpPageChange(*mpSdrPage);
1188 break;
1190 case SFX_HINT_DYING :
1192 // Style needs to be forgotten
1193 ImpRemoveStyleSheet();
1194 break;
1200 bool SdrPageProperties::isUsedByModel() const
1202 assert(mpSdrPage);
1203 return mpSdrPage->IsInserted();
1206 const SfxItemSet& SdrPageProperties::GetItemSet() const
1208 return *mpProperties;
1211 void SdrPageProperties::PutItemSet(const SfxItemSet& rSet)
1213 OSL_ENSURE(!mpSdrPage->IsMasterPage(), "Item set at MasterPage Attributes (!)");
1214 mpProperties->Put(rSet);
1215 ImpPageChange(*mpSdrPage);
1218 void SdrPageProperties::PutItem(const SfxPoolItem& rItem)
1220 OSL_ENSURE(!mpSdrPage->IsMasterPage(), "Item set at MasterPage Attributes (!)");
1221 mpProperties->Put(rItem);
1222 ImpPageChange(*mpSdrPage);
1225 void SdrPageProperties::ClearItem(const sal_uInt16 nWhich)
1227 mpProperties->ClearItem(nWhich);
1228 ImpPageChange(*mpSdrPage);
1231 void SdrPageProperties::SetStyleSheet(SfxStyleSheet* pStyleSheet)
1233 if(pStyleSheet)
1235 ImpAddStyleSheet(*pStyleSheet);
1237 else
1239 ImpRemoveStyleSheet();
1242 ImpPageChange(*mpSdrPage);
1245 SfxStyleSheet* SdrPageProperties::GetStyleSheet() const
1247 return mpStyleSheet;
1250 ////////////////////////////////////////////////////////////////////////////////////////////////////
1252 TYPEINIT1(SdrPage,SdrObjList);
1253 DBG_NAME(SdrPage)
1254 SdrPage::SdrPage(SdrModel& rNewModel, bool bMasterPage)
1255 : SdrObjList(&rNewModel, this),
1256 mpViewContact(0L),
1257 nWdt(10L),
1258 nHgt(10L),
1259 nBordLft(0L),
1260 nBordUpp(0L),
1261 nBordRgt(0L),
1262 nBordLwr(0L),
1263 pLayerAdmin(new SdrLayerAdmin(&rNewModel.GetLayerAdmin())),
1264 mpSdrPageProperties(0),
1265 mpMasterPageDescriptor(0L),
1266 nPageNum(0L),
1267 mbMaster(bMasterPage),
1268 mbInserted(false),
1269 mbObjectsNotPersistent(false),
1270 mbSwappingLocked(false),
1271 mbPageBorderOnlyLeftRight(false)
1273 DBG_CTOR(SdrPage,NULL);
1274 aPrefVisiLayers.SetAll();
1275 eListKind = (bMasterPage) ? SDROBJLIST_MASTERPAGE : SDROBJLIST_DRAWPAGE;
1277 mpSdrPageProperties = new SdrPageProperties(*this);
1280 SdrPage::SdrPage(const SdrPage& rSrcPage)
1281 : SdrObjList(rSrcPage.pModel, this),
1282 tools::WeakBase< SdrPage >(),
1283 mpViewContact(0L),
1284 nWdt(rSrcPage.nWdt),
1285 nHgt(rSrcPage.nHgt),
1286 nBordLft(rSrcPage.nBordLft),
1287 nBordUpp(rSrcPage.nBordUpp),
1288 nBordRgt(rSrcPage.nBordRgt),
1289 nBordLwr(rSrcPage.nBordLwr),
1290 pLayerAdmin(new SdrLayerAdmin(rSrcPage.pModel->GetLayerAdmin())),
1291 mpSdrPageProperties(0),
1292 mpMasterPageDescriptor(0L),
1293 nPageNum(rSrcPage.nPageNum),
1294 mbMaster(rSrcPage.mbMaster),
1295 mbInserted(false),
1296 mbObjectsNotPersistent(rSrcPage.mbObjectsNotPersistent),
1297 mbSwappingLocked(rSrcPage.mbSwappingLocked),
1298 mbPageBorderOnlyLeftRight(rSrcPage.mbPageBorderOnlyLeftRight)
1300 DBG_CTOR(SdrPage,NULL);
1301 aPrefVisiLayers.SetAll();
1302 eListKind = (mbMaster) ? SDROBJLIST_MASTERPAGE : SDROBJLIST_DRAWPAGE;
1304 // copy things from source
1305 // Warning: this leads to slicing (see issue 93186) and has to be
1306 // removed as soon as possible.
1307 *this = rSrcPage;
1308 OSL_ENSURE(mpSdrPageProperties,
1309 "SdrPage::SdrPage: operator= did not create needed SdrPageProperties (!)");
1311 // be careful and correct eListKind, a member of SdrObjList which
1312 // will be changed by the SdrOIbjList::operator= before...
1313 eListKind = (mbMaster) ? SDROBJLIST_MASTERPAGE : SDROBJLIST_DRAWPAGE;
1315 // The previous assignment to *this may have resulted in a call to
1316 // createUnoPage at a partially initialized (sliced) SdrPage object.
1317 // Due to the vtable being not yet fully set-up at this stage,
1318 // createUnoPage() may have been called at the wrong class.
1319 // To force a call to the right createUnoPage() at a later time when the
1320 // new object is full constructed mxUnoPage is disposed now.
1321 uno::Reference<lang::XComponent> xComponent (mxUnoPage, uno::UNO_QUERY);
1322 if (xComponent.is())
1324 mxUnoPage = NULL;
1325 xComponent->dispose();
1329 SdrPage::~SdrPage()
1331 if( mxUnoPage.is() ) try
1333 uno::Reference< lang::XComponent > xPageComponent( mxUnoPage, uno::UNO_QUERY_THROW );
1334 mxUnoPage.clear();
1335 xPageComponent->dispose();
1337 catch( const uno::Exception& )
1339 DBG_UNHANDLED_EXCEPTION();
1342 // tell all the registered PageUsers that the page is in destruction
1343 // This causes some (all?) PageUsers to remove themselves from the list
1344 // of page users. Therefore we have to use a copy of the list for the
1345 // iteration.
1346 ::sdr::PageUserVector aListCopy (maPageUsers.begin(), maPageUsers.end());
1347 for(::sdr::PageUserVector::iterator aIterator = aListCopy.begin(); aIterator != aListCopy.end(); ++aIterator)
1349 sdr::PageUser* pPageUser = *aIterator;
1350 DBG_ASSERT(pPageUser, "SdrPage::~SdrPage: corrupt PageUser list (!)");
1351 pPageUser->PageInDestruction(*this);
1354 // Clear the vector. This means that user do not need to call RemovePageUser()
1355 // when they get called from PageInDestruction().
1356 maPageUsers.clear();
1358 delete pLayerAdmin;
1360 TRG_ClearMasterPage();
1362 if(mpViewContact)
1364 delete mpViewContact;
1365 mpViewContact = 0L;
1369 delete mpSdrPageProperties;
1370 mpSdrPageProperties = 0;
1373 DBG_DTOR(SdrPage,NULL);
1376 SdrPage& SdrPage::operator=(const SdrPage& rSrcPage)
1378 if( this == &rSrcPage )
1379 return *this;
1380 if(mpViewContact)
1382 delete mpViewContact;
1383 mpViewContact = 0L;
1386 // Joe also sets some parameters for the class this one
1387 // is derived from. SdrObjList does the same bad handling of
1388 // copy constructor and operator=, so i better let it stand here.
1389 pPage = this;
1391 // copy all the local parameters to make this instance
1392 // a valid copy of source page before copying and inserting
1393 // the contained objects
1394 mbMaster = rSrcPage.mbMaster;
1395 mbSwappingLocked = rSrcPage.mbSwappingLocked;
1396 mbPageBorderOnlyLeftRight = rSrcPage.mbPageBorderOnlyLeftRight;
1397 aPrefVisiLayers = rSrcPage.aPrefVisiLayers;
1398 nWdt = rSrcPage.nWdt;
1399 nHgt = rSrcPage.nHgt;
1400 nBordLft = rSrcPage.nBordLft;
1401 nBordUpp = rSrcPage.nBordUpp;
1402 nBordRgt = rSrcPage.nBordRgt;
1403 nBordLwr = rSrcPage.nBordLwr;
1404 nPageNum = rSrcPage.nPageNum;
1406 if(rSrcPage.TRG_HasMasterPage())
1408 TRG_SetMasterPage(rSrcPage.TRG_GetMasterPage());
1409 TRG_SetMasterPageVisibleLayers(rSrcPage.TRG_GetMasterPageVisibleLayers());
1411 else
1413 TRG_ClearMasterPage();
1416 mbObjectsNotPersistent = rSrcPage.mbObjectsNotPersistent;
1419 // #i111122# delete SdrPageProperties when model is different
1420 if(mpSdrPageProperties && GetModel() != rSrcPage.GetModel())
1422 delete mpSdrPageProperties;
1423 mpSdrPageProperties = 0;
1426 if(!mpSdrPageProperties)
1428 mpSdrPageProperties = new SdrPageProperties(*this);
1430 else
1432 mpSdrPageProperties->ClearItem(0);
1435 if(!IsMasterPage())
1437 mpSdrPageProperties->PutItemSet(rSrcPage.getSdrPageProperties().GetItemSet());
1440 mpSdrPageProperties->SetStyleSheet(rSrcPage.getSdrPageProperties().GetStyleSheet());
1443 // Now copy the contained objects (by cloning them)
1444 SdrObjList::operator=(rSrcPage);
1445 return *this;
1448 SdrPage* SdrPage::Clone() const
1450 return Clone(NULL);
1453 SdrPage* SdrPage::Clone(SdrModel* pNewModel) const
1455 if (pNewModel==NULL) pNewModel=pModel;
1456 SdrPage* pPage2=new SdrPage(*pNewModel);
1457 *pPage2=*this;
1458 return pPage2;
1461 void SdrPage::SetSize(const Size& aSiz)
1463 bool bChanged(false);
1465 if(aSiz.Width() != nWdt)
1467 nWdt = aSiz.Width();
1468 bChanged = true;
1471 if(aSiz.Height() != nHgt)
1473 nHgt = aSiz.Height();
1474 bChanged = true;
1477 if(bChanged)
1479 SetChanged();
1483 Size SdrPage::GetSize() const
1485 return Size(nWdt,nHgt);
1488 sal_Int32 SdrPage::GetWdt() const
1490 return nWdt;
1493 void SdrPage::SetOrientation(Orientation eOri)
1495 // square: handle like portrait format
1496 Size aSiz(GetSize());
1497 if (aSiz.Width()!=aSiz.Height()) {
1498 if ((eOri==ORIENTATION_PORTRAIT) == (aSiz.Width()>aSiz.Height())) {
1499 SetSize(Size(aSiz.Height(),aSiz.Width()));
1504 Orientation SdrPage::GetOrientation() const
1506 // square: handle like portrait format
1507 Orientation eRet=ORIENTATION_PORTRAIT;
1508 Size aSiz(GetSize());
1509 if (aSiz.Width()>aSiz.Height()) eRet=ORIENTATION_LANDSCAPE;
1510 return eRet;
1513 sal_Int32 SdrPage::GetHgt() const
1515 return nHgt;
1518 void SdrPage::SetBorder(sal_Int32 nLft, sal_Int32 nUpp, sal_Int32 nRgt, sal_Int32 nLwr)
1520 bool bChanged(false);
1522 if(nBordLft != nLft)
1524 nBordLft = nLft;
1525 bChanged = true;
1528 if(nBordUpp != nUpp)
1530 nBordUpp = nUpp;
1531 bChanged = true;
1534 if(nBordRgt != nRgt)
1536 nBordRgt = nRgt;
1537 bChanged = true;
1540 if(nBordLwr != nLwr)
1542 nBordLwr = nLwr;
1543 bChanged = true;
1546 if(bChanged)
1548 SetChanged();
1552 void SdrPage::SetLftBorder(sal_Int32 nBorder)
1554 if(nBordLft != nBorder)
1556 nBordLft = nBorder;
1557 SetChanged();
1561 void SdrPage::SetUppBorder(sal_Int32 nBorder)
1563 if(nBordUpp != nBorder)
1565 nBordUpp = nBorder;
1566 SetChanged();
1570 void SdrPage::SetRgtBorder(sal_Int32 nBorder)
1572 if(nBordRgt != nBorder)
1574 nBordRgt=nBorder;
1575 SetChanged();
1579 void SdrPage::SetLwrBorder(sal_Int32 nBorder)
1581 if(nBordLwr != nBorder)
1583 nBordLwr=nBorder;
1584 SetChanged();
1588 sal_Int32 SdrPage::GetLftBorder() const
1590 return nBordLft;
1593 sal_Int32 SdrPage::GetUppBorder() const
1595 return nBordUpp;
1598 sal_Int32 SdrPage::GetRgtBorder() const
1600 return nBordRgt;
1603 sal_Int32 SdrPage::GetLwrBorder() const
1605 return nBordLwr;
1608 void SdrPage::SetModel(SdrModel* pNewModel)
1610 SdrModel* pOldModel=pModel;
1611 SdrObjList::SetModel(pNewModel);
1612 if (pNewModel!=pOldModel)
1614 if (pNewModel!=NULL) {
1615 pLayerAdmin->SetParent(&pNewModel->GetLayerAdmin());
1616 } else {
1617 pLayerAdmin->SetParent(NULL);
1619 pLayerAdmin->SetModel(pNewModel);
1621 // create new SdrPageProperties with new model (due to SfxItemSet there)
1622 // and copy ItemSet and StyleSheet
1623 SdrPageProperties *pNew = new SdrPageProperties(*this);
1625 if(!IsMasterPage())
1627 pNew->PutItemSet(getSdrPageProperties().GetItemSet());
1630 pNew->SetStyleSheet(getSdrPageProperties().GetStyleSheet());
1632 delete mpSdrPageProperties;
1633 mpSdrPageProperties = pNew;
1636 // update listeners at possible API wrapper object
1637 if( pOldModel != pNewModel )
1639 if( mxUnoPage.is() )
1641 SvxDrawPage* pPage2 = SvxDrawPage::getImplementation( mxUnoPage );
1642 if( pPage2 )
1643 pPage2->ChangeModel( pNewModel );
1648 ////////////////////////////////////////////////////////////////////////////////////////////////////
1650 // #i68775# React on PageNum changes (from Model in most cases)
1651 void SdrPage::SetPageNum(sal_uInt16 nNew)
1653 if(nNew != nPageNum)
1655 // change
1656 nPageNum = nNew;
1658 // notify visualisations, also notifies e.g. buffered MasterPages
1659 ActionChanged();
1663 sal_uInt16 SdrPage::GetPageNum() const
1665 if (!mbInserted)
1666 return 0;
1668 if (mbMaster) {
1669 if (pModel && pModel->IsMPgNumsDirty())
1670 ((SdrModel*)pModel)->RecalcPageNums(sal_True);
1671 } else {
1672 if (pModel && pModel->IsPagNumsDirty())
1673 ((SdrModel*)pModel)->RecalcPageNums(sal_False);
1675 return nPageNum;
1678 void SdrPage::SetChanged()
1680 // For test purposes, use the new ViewContact for change
1681 // notification now.
1682 ActionChanged();
1684 if( pModel )
1686 pModel->SetChanged();
1690 ////////////////////////////////////////////////////////////////////////////////////////////////////
1691 // MasterPage interface
1693 void SdrPage::TRG_SetMasterPage(SdrPage& rNew)
1695 if(mpMasterPageDescriptor && &(mpMasterPageDescriptor->GetUsedPage()) == &rNew)
1696 return;
1698 if(mpMasterPageDescriptor)
1699 TRG_ClearMasterPage();
1701 mpMasterPageDescriptor = new ::sdr::MasterPageDescriptor(*this, rNew);
1702 GetViewContact().ActionChanged();
1705 void SdrPage::TRG_ClearMasterPage()
1707 if(mpMasterPageDescriptor)
1709 SetChanged();
1711 // the flushViewObjectContacts() will do needed invalidates by deleting the involved VOCs
1712 mpMasterPageDescriptor->GetUsedPage().GetViewContact().flushViewObjectContacts(true);
1714 delete mpMasterPageDescriptor;
1715 mpMasterPageDescriptor = 0L;
1719 SdrPage& SdrPage::TRG_GetMasterPage() const
1721 DBG_ASSERT(mpMasterPageDescriptor != 0L, "TRG_GetMasterPage(): No MasterPage available. Use TRG_HasMasterPage() before access (!)");
1722 return mpMasterPageDescriptor->GetUsedPage();
1725 const SetOfByte& SdrPage::TRG_GetMasterPageVisibleLayers() const
1727 DBG_ASSERT(mpMasterPageDescriptor != 0L, "TRG_GetMasterPageVisibleLayers(): No MasterPage available. Use TRG_HasMasterPage() before access (!)");
1728 return mpMasterPageDescriptor->GetVisibleLayers();
1731 void SdrPage::TRG_SetMasterPageVisibleLayers(const SetOfByte& rNew)
1733 DBG_ASSERT(mpMasterPageDescriptor != 0L, "TRG_SetMasterPageVisibleLayers(): No MasterPage available. Use TRG_HasMasterPage() before access (!)");
1734 mpMasterPageDescriptor->SetVisibleLayers(rNew);
1737 sdr::contact::ViewContact& SdrPage::TRG_GetMasterPageDescriptorViewContact() const
1739 DBG_ASSERT(mpMasterPageDescriptor != 0L, "TRG_GetMasterPageDescriptorViewContact(): No MasterPage available. Use TRG_HasMasterPage() before access (!)");
1740 return mpMasterPageDescriptor->GetViewContact();
1743 // used from SdrModel::RemoveMasterPage
1744 void SdrPage::TRG_ImpMasterPageRemoved(const SdrPage& rRemovedPage)
1746 if(TRG_HasMasterPage())
1748 if(&TRG_GetMasterPage() == &rRemovedPage)
1750 TRG_ClearMasterPage();
1755 const SdrPageGridFrameList* SdrPage::GetGridFrameList(const SdrPageView* /*pPV*/, const Rectangle* /*pRect*/) const
1757 return NULL;
1760 OUString SdrPage::GetLayoutName() const
1762 return OUString();
1765 void SdrPage::SetInserted( bool bIns )
1767 if( (bool) mbInserted != bIns )
1769 mbInserted = bIns;
1771 // #i120437# go over whole hierarchy, not only over object level null (seen from grouping)
1772 SdrObjListIter aIter(*this, IM_DEEPNOGROUPS);
1774 while ( aIter.IsMore() )
1776 SdrObject* pObj = aIter.Next();
1777 if ( pObj->ISA(SdrOle2Obj) )
1779 if( mbInserted )
1780 ( (SdrOle2Obj*) pObj)->Connect();
1781 else
1782 ( (SdrOle2Obj*) pObj)->Disconnect();
1788 void SdrPage::SetUnoPage(uno::Reference<drawing::XDrawPage> const& xNewPage)
1790 mxUnoPage = xNewPage;
1793 uno::Reference< uno::XInterface > SdrPage::getUnoPage()
1795 if( !mxUnoPage.is() )
1797 // create one
1798 mxUnoPage = createUnoPage();
1801 return mxUnoPage;
1804 uno::Reference< uno::XInterface > SdrPage::createUnoPage()
1806 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xInt =
1807 static_cast<cppu::OWeakObject*>( new SvxFmDrawPage( this ) );
1808 return xInt;
1811 SfxStyleSheet* SdrPage::GetTextStyleSheetForObject( SdrObject* pObj ) const
1813 return pObj->GetStyleSheet();
1816 /** returns an averaged background color of this page */
1817 // #i75566# GetBackgroundColor -> GetPageBackgroundColor and bScreenDisplay hint value
1818 Color SdrPage::GetPageBackgroundColor( SdrPageView* pView, bool bScreenDisplay ) const
1820 Color aColor;
1822 if(bScreenDisplay && (!pView || pView->GetApplicationDocumentColor() == COL_AUTO))
1824 svtools::ColorConfig aColorConfig;
1825 aColor = aColorConfig.GetColorValue( svtools::DOCCOLOR ).nColor;
1827 else
1829 aColor = pView->GetApplicationDocumentColor();
1832 const SfxItemSet* pBackgroundFill = &getSdrPageProperties().GetItemSet();
1834 if(!IsMasterPage() && TRG_HasMasterPage())
1836 if(XFILL_NONE == ((const XFillStyleItem&)pBackgroundFill->Get(XATTR_FILLSTYLE)).GetValue())
1838 pBackgroundFill = &TRG_GetMasterPage().getSdrPageProperties().GetItemSet();
1842 GetDraftFillColor(*pBackgroundFill, aColor);
1844 return aColor;
1847 /** *deprecated, use GetBackgroundColor with SdrPageView */
1848 Color SdrPage::GetPageBackgroundColor() const
1849 // #i75566# GetBackgroundColor -> GetPageBackgroundColor
1851 return GetPageBackgroundColor( NULL, true );
1854 /** this method returns true if the object from the ViewObjectContact should
1855 be visible on this page while rendering.
1856 bEdit selects if visibility test is for an editing view or a final render,
1857 like printing.
1859 bool SdrPage::checkVisibility(
1860 const sdr::contact::ViewObjectContact& /*rOriginal*/,
1861 const sdr::contact::DisplayInfo& /*rDisplayInfo*/,
1862 bool /*bEdit*/)
1864 // this will be handled in the application if needed
1865 return true;
1868 // DrawContact support: Methods for handling Page changes
1869 void SdrPage::ActionChanged() const
1871 // Do necessary ViewContact actions
1872 GetViewContact().ActionChanged();
1874 // #i48535# also handle MasterPage change
1875 if(TRG_HasMasterPage())
1877 TRG_GetMasterPageDescriptorViewContact().ActionChanged();
1881 //////////////////////////////////////////////////////////////////////////////
1882 // sdr::Comment interface
1884 const SdrPageProperties* SdrPage::getCorrectSdrPageProperties() const
1886 if(mpMasterPageDescriptor)
1888 return mpMasterPageDescriptor->getCorrectSdrPageProperties();
1890 else
1892 return &getSdrPageProperties();
1896 //////////////////////////////////////////////////////////////////////////////
1897 // use new redirector instead of pPaintProc
1899 StandardCheckVisisbilityRedirector::StandardCheckVisisbilityRedirector()
1900 : ViewObjectContactRedirector()
1904 StandardCheckVisisbilityRedirector::~StandardCheckVisisbilityRedirector()
1908 drawinglayer::primitive2d::Primitive2DSequence StandardCheckVisisbilityRedirector::createRedirectedPrimitive2DSequence(
1909 const sdr::contact::ViewObjectContact& rOriginal,
1910 const sdr::contact::DisplayInfo& rDisplayInfo)
1912 SdrObject* pObject = rOriginal.GetViewContact().TryToGetSdrObject();
1914 if(pObject)
1916 if(pObject->GetPage())
1918 if(pObject->GetPage()->checkVisibility(rOriginal, rDisplayInfo, false))
1920 return ::sdr::contact::ViewObjectContactRedirector::createRedirectedPrimitive2DSequence(rOriginal, rDisplayInfo);
1924 return drawinglayer::primitive2d::Primitive2DSequence();
1926 else
1928 // not an object, maybe a page
1929 return ::sdr::contact::ViewObjectContactRedirector::createRedirectedPrimitive2DSequence(rOriginal, rDisplayInfo);
1934 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */