Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / svx / source / svdraw / svdpage.cxx
blobb0a9c4477c6e0bd165d4c298b3437e1bb3a1083d
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>
38 #include <svx/svdoedge.hxx>
39 #include <svx/svdoole2.hxx>
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 <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);
73 TYPEINIT0(SdrObjList);
75 SdrObjList::SdrObjList(SdrModel* pNewModel, SdrPage* pNewPage, SdrObjList* pNewUpList):
76 maList(),
77 mpNavigationOrder(),
78 mbIsNavigationOrderDirty(false)
80 maList.reserve(InitialObjectContainerCapacity);
81 pModel=pNewModel;
82 pPage=pNewPage;
83 pUpList=pNewUpList;
84 bObjOrdNumsDirty=false;
85 bRectsDirty=false;
86 pOwnerObj=NULL;
87 eListKind=SDROBJLIST_UNKNOWN;
90 SdrObjList::SdrObjList(const SdrObjList& rSrcList):
91 maList(),
92 mpNavigationOrder(),
93 mbIsNavigationOrderDirty(false)
95 maList.reserve(InitialObjectContainerCapacity);
96 pModel=NULL;
97 pPage=NULL;
98 pUpList=NULL;
99 bObjOrdNumsDirty=false;
100 bRectsDirty=false;
101 pOwnerObj=NULL;
102 eListKind=SDROBJLIST_UNKNOWN;
103 *this=rSrcList;
106 SdrObjList::~SdrObjList()
109 // To avoid that the Clear() method will broadcast changes when in destruction
110 // which would call virtual methos (not allowed in destructor), the model is set
111 // to NULL here.
112 pModel = 0L;
114 Clear(); // delete contents of container
117 void SdrObjList::operator=(const SdrObjList& rSrcList)
119 Clear();
120 eListKind=rSrcList.eListKind;
121 CopyObjects(rSrcList);
124 void SdrObjList::CopyObjects(const SdrObjList& rSrcList)
126 Clear();
127 bObjOrdNumsDirty=false;
128 bRectsDirty =false;
129 sal_uIntPtr nCloneErrCnt=0;
130 sal_uIntPtr nAnz=rSrcList.GetObjCount();
131 SdrInsertReason aReason(SDRREASON_COPY);
132 sal_uIntPtr no;
133 for (no=0; no<nAnz; no++) {
134 SdrObject* pSO=rSrcList.GetObj(no);
136 SdrObject* pDO = pSO->Clone();
138 if (pDO!=NULL) {
139 pDO->SetModel(pModel);
140 pDO->SetPage(pPage);
141 NbcInsertObject(pDO,CONTAINER_APPEND,&aReason);
142 } else {
143 nCloneErrCnt++;
147 // and now for the Connectors
148 // The new objects would be shown in the rSrcList
149 // and then the object connections are made.
150 // Similar implementation are setup as the following:
151 // void SdrObjList::CopyObjects(const SdrObjList& rSrcList)
152 // SdrModel* SdrExchangeView::GetMarkedObjModel() const
153 // BOOL SdrExchangeView::Paste(const SdrModel& rMod,...)
154 // void SdrEditView::CopyMarked()
155 if (nCloneErrCnt==0) {
156 for (no=0; no<nAnz; no++) {
157 const SdrObject* pSrcOb=rSrcList.GetObj(no);
158 SdrEdgeObj* pSrcEdge=PTR_CAST(SdrEdgeObj,pSrcOb);
159 if (pSrcEdge!=NULL) {
160 SdrObject* pSrcNode1=pSrcEdge->GetConnectedNode(true);
161 SdrObject* pSrcNode2=pSrcEdge->GetConnectedNode(false);
162 if (pSrcNode1!=NULL && pSrcNode1->GetObjList()!=pSrcEdge->GetObjList()) pSrcNode1=NULL; // can't do this
163 if (pSrcNode2!=NULL && pSrcNode2->GetObjList()!=pSrcEdge->GetObjList()) pSrcNode2=NULL; // across all lists (yet)
164 if (pSrcNode1!=NULL || pSrcNode2!=NULL) {
165 SdrObject* pEdgeObjTmp=GetObj(no);
166 SdrEdgeObj* pDstEdge=PTR_CAST(SdrEdgeObj,pEdgeObjTmp);
167 if (pDstEdge!=NULL) {
168 if (pSrcNode1!=NULL) {
169 sal_uIntPtr nDstNode1=pSrcNode1->GetOrdNum();
170 SdrObject* pDstNode1=GetObj(nDstNode1);
171 if (pDstNode1!=NULL) { // else we get an error!
172 pDstEdge->ConnectToNode(true,pDstNode1);
173 } else {
174 OSL_FAIL("SdrObjList::operator=(): pDstNode1==NULL!");
177 if (pSrcNode2!=NULL) {
178 sal_uIntPtr nDstNode2=pSrcNode2->GetOrdNum();
179 SdrObject* pDstNode2=GetObj(nDstNode2);
180 if (pDstNode2!=NULL) { // else the node was probably not selected
181 pDstEdge->ConnectToNode(false,pDstNode2);
182 } else {
183 OSL_FAIL("SdrObjList::operator=(): pDstNode2==NULL!");
186 } else {
187 OSL_FAIL("SdrObjList::operator=(): pDstEdge==NULL!");
192 } else {
193 #ifdef DBG_UTIL
194 OStringBuffer aStr("SdrObjList::operator=(): Error when cloning ");
196 if(nCloneErrCnt == 1)
198 aStr.append("a drawing object.");
200 else
202 aStr.append(static_cast<sal_Int32>(nCloneErrCnt));
203 aStr.append(" drawing objects.");
206 aStr.append(" Not copying connectors.");
208 OSL_FAIL(aStr.getStr());
209 #endif
213 void SdrObjList::Clear()
215 bool bObjectsRemoved(false);
217 while( ! maList.empty())
219 // remove last object from list
220 SdrObject* pObj = maList.back();
221 RemoveObjectFromContainer(maList.size()-1);
223 // flushViewObjectContacts() is done since SdrObject::Free is not guaranteed
224 // to delete the object and thus refresh visualisations
225 pObj->GetViewContact().flushViewObjectContacts(true);
227 bObjectsRemoved = true;
229 // sent remove hint (after removal, see RemoveObject())
230 if(pModel)
232 SdrHint aHint(*pObj);
233 aHint.SetKind(HINT_OBJREMOVED);
234 aHint.SetPage(pPage);
235 pModel->Broadcast(aHint);
238 // delete the object itself
239 SdrObject::Free( pObj );
242 if(pModel && bObjectsRemoved)
244 pModel->SetChanged();
248 SdrPage* SdrObjList::GetPage() const
250 return pPage;
253 void SdrObjList::SetPage(SdrPage* pNewPage)
255 if (pPage!=pNewPage) {
256 pPage=pNewPage;
257 sal_uIntPtr nAnz=GetObjCount();
258 for (sal_uIntPtr no=0; no<nAnz; no++) {
259 SdrObject* pObj=GetObj(no);
260 pObj->SetPage(pPage);
265 SdrModel* SdrObjList::GetModel() const
267 return pModel;
270 void SdrObjList::SetModel(SdrModel* pNewModel)
272 if (pModel!=pNewModel) {
273 pModel=pNewModel;
274 sal_uIntPtr nAnz=GetObjCount();
275 for (sal_uIntPtr i=0; i<nAnz; i++) {
276 SdrObject* pObj=GetObj(i);
277 pObj->SetModel(pModel);
282 void SdrObjList::RecalcObjOrdNums()
284 sal_uIntPtr nAnz=GetObjCount();
285 for (sal_uIntPtr no=0; no<nAnz; no++) {
286 SdrObject* pObj=GetObj(no);
287 pObj->SetOrdNum(no);
289 bObjOrdNumsDirty=false;
292 void SdrObjList::RecalcRects()
294 aOutRect=Rectangle();
295 aSnapRect=aOutRect;
296 sal_uIntPtr nAnz=GetObjCount();
297 sal_uIntPtr i;
298 for (i=0; i<nAnz; i++) {
299 SdrObject* pObj=GetObj(i);
300 if (i==0) {
301 aOutRect=pObj->GetCurrentBoundRect();
302 aSnapRect=pObj->GetSnapRect();
303 } else {
304 aOutRect.Union(pObj->GetCurrentBoundRect());
305 aSnapRect.Union(pObj->GetSnapRect());
310 void SdrObjList::SetRectsDirty()
312 bRectsDirty=true;
313 if (pUpList!=NULL) pUpList->SetRectsDirty();
316 void SdrObjList::impChildInserted(SdrObject& rChild) const
318 sdr::contact::ViewContact* pParent = rChild.GetViewContact().GetParentContact();
320 if(pParent)
322 pParent->ActionChildInserted(rChild.GetViewContact());
326 void SdrObjList::NbcInsertObject(SdrObject* pObj, sal_uIntPtr nPos, const SdrInsertReason* /*pReason*/)
328 DBG_ASSERT(pObj!=NULL,"SdrObjList::NbcInsertObject(NULL)");
329 if (pObj!=NULL) {
330 DBG_ASSERT(!pObj->IsInserted(),"ZObjekt already has the status Inserted.");
331 sal_uIntPtr nAnz=GetObjCount();
332 if (nPos>nAnz) nPos=nAnz;
333 InsertObjectIntoContainer(*pObj,nPos);
335 if (nPos<nAnz) bObjOrdNumsDirty=true;
336 pObj->SetOrdNum(nPos);
337 pObj->SetObjList(this);
338 pObj->SetPage(pPage);
340 // Inform the parent about change to allow invalidations at
341 // evtl. existing parent visualisations
342 impChildInserted(*pObj);
344 if (!bRectsDirty) {
345 aOutRect.Union(pObj->GetCurrentBoundRect());
346 aSnapRect.Union(pObj->GetSnapRect());
348 pObj->SetInserted(true); // calls the UserCall (among others)
352 void SdrObjList::InsertObject(SdrObject* pObj, sal_uIntPtr nPos, const SdrInsertReason* pReason)
354 DBG_ASSERT(pObj!=NULL,"SdrObjList::InsertObject(NULL)");
356 if(pObj)
358 // if anchor is used, reset it before grouping
359 if(GetOwnerObj())
361 const Point& rAnchorPos = pObj->GetAnchorPos();
362 if(rAnchorPos.X() || rAnchorPos.Y())
363 pObj->NbcSetAnchorPos(Point());
366 // do insert to new group
367 NbcInsertObject(pObj, nPos, pReason);
369 // In case the object is inserted into a group and doesn't overlap with
370 // the group's other members, it needs an own repaint.
371 if(pOwnerObj)
373 // only repaint here
374 pOwnerObj->ActionChanged();
377 if(pModel)
379 // TODO: We need a different broadcast here!
380 // Repaint from object number ... (heads-up: GroupObj)
381 if(pObj->GetPage())
383 SdrHint aHint(*pObj);
385 aHint.SetKind(HINT_OBJINSERTED);
386 pModel->Broadcast(aHint);
389 pModel->SetChanged();
394 SdrObject* SdrObjList::NbcRemoveObject(sal_uIntPtr nObjNum)
396 if (nObjNum >= maList.size())
398 OSL_ASSERT(nObjNum<maList.size());
399 return NULL;
402 sal_uIntPtr nAnz=GetObjCount();
403 SdrObject* pObj=maList[nObjNum];
404 RemoveObjectFromContainer(nObjNum);
406 DBG_ASSERT(pObj!=NULL,"Could not find object to remove.");
407 if (pObj!=NULL) {
408 // flushViewObjectContacts() clears the VOC's and those invalidate
409 pObj->GetViewContact().flushViewObjectContacts(true);
411 DBG_ASSERT(pObj->IsInserted(),"ZObjekt does not have the status Inserted.");
412 pObj->SetInserted(false); // Ruft u.a. den UserCall
413 pObj->SetObjList(NULL);
414 pObj->SetPage(NULL);
415 if (!bObjOrdNumsDirty) { // optimizing for the case that the last object has to be removed
416 if (nObjNum!=sal_uIntPtr(nAnz-1)) {
417 bObjOrdNumsDirty=true;
420 SetRectsDirty();
422 return pObj;
425 SdrObject* SdrObjList::RemoveObject(sal_uIntPtr nObjNum)
427 if (nObjNum >= maList.size())
429 OSL_ASSERT(nObjNum<maList.size());
430 return NULL;
433 sal_uIntPtr nAnz=GetObjCount();
434 SdrObject* pObj=maList[nObjNum];
435 RemoveObjectFromContainer(nObjNum);
437 DBG_ASSERT(pObj!=NULL,"Object to remove not found.");
438 if(pObj)
440 // flushViewObjectContacts() clears the VOC's and those invalidate
441 pObj->GetViewContact().flushViewObjectContacts(true);
443 DBG_ASSERT(pObj->IsInserted(),"ZObjekt does not have the status Inserted.");
444 if (pModel!=NULL) {
445 // TODO: We need a different broadcast here.
446 if (pObj->GetPage()!=NULL) {
447 SdrHint aHint(*pObj);
448 aHint.SetKind(HINT_OBJREMOVED);
449 pModel->Broadcast(aHint);
451 pModel->SetChanged();
453 pObj->SetInserted(false); // calls, among other things, the UserCall
454 pObj->SetObjList(NULL);
455 pObj->SetPage(NULL);
456 if (!bObjOrdNumsDirty) { // optimization for the case that the last object is removed
457 if (nObjNum!=sal_uIntPtr(nAnz-1)) {
458 bObjOrdNumsDirty=true;
461 SetRectsDirty();
463 if(pOwnerObj && !GetObjCount())
465 // empty group created; it needs to be repainted since it's
466 // visualization changes
467 pOwnerObj->ActionChanged();
470 return pObj;
473 SdrObject* SdrObjList::NbcReplaceObject(SdrObject* pNewObj, sal_uIntPtr nObjNum)
475 if (nObjNum >= maList.size() || pNewObj == NULL)
477 OSL_ASSERT(nObjNum<maList.size());
478 OSL_ASSERT(pNewObj!=NULL);
479 return NULL;
482 SdrObject* pObj=maList[nObjNum];
483 DBG_ASSERT(pObj!=NULL,"SdrObjList::ReplaceObject: Could not find object to remove.");
484 if (pObj!=NULL) {
485 DBG_ASSERT(pObj->IsInserted(),"SdrObjList::ReplaceObject: ZObjekt does not have status Inserted.");
486 pObj->SetInserted(false);
487 pObj->SetObjList(NULL);
488 pObj->SetPage(NULL);
489 ReplaceObjectInContainer(*pNewObj,nObjNum);
491 // flushViewObjectContacts() clears the VOC's and those invalidate
492 pObj->GetViewContact().flushViewObjectContacts(true);
494 pNewObj->SetOrdNum(nObjNum);
495 pNewObj->SetObjList(this);
496 pNewObj->SetPage(pPage);
498 // Inform the parent about change to allow invalidations at
499 // evtl. existing parent visualisations
500 impChildInserted(*pNewObj);
502 pNewObj->SetInserted(true);
503 SetRectsDirty();
505 return pObj;
508 SdrObject* SdrObjList::ReplaceObject(SdrObject* pNewObj, sal_uIntPtr nObjNum)
510 if (nObjNum >= maList.size())
512 OSL_ASSERT(nObjNum<maList.size());
513 return NULL;
515 if (pNewObj == NULL)
517 OSL_ASSERT(pNewObj!=NULL);
518 return NULL;
521 SdrObject* pObj=maList[nObjNum];
522 DBG_ASSERT(pObj!=NULL,"SdrObjList::ReplaceObject: Could not find object to remove.");
523 if (pObj!=NULL) {
524 DBG_ASSERT(pObj->IsInserted(),"SdrObjList::ReplaceObject: ZObjekt does not have status Inserted.");
525 if (pModel!=NULL) {
526 // TODO: We need a different broadcast here.
527 if (pObj->GetPage()!=NULL) {
528 SdrHint aHint(*pObj);
529 aHint.SetKind(HINT_OBJREMOVED);
530 pModel->Broadcast(aHint);
533 pObj->SetInserted(false);
534 pObj->SetObjList(NULL);
535 pObj->SetPage(NULL);
536 ReplaceObjectInContainer(*pNewObj,nObjNum);
538 // flushViewObjectContacts() clears the VOC's and those invalidate
539 pObj->GetViewContact().flushViewObjectContacts(true);
541 pNewObj->SetOrdNum(nObjNum);
542 pNewObj->SetObjList(this);
543 pNewObj->SetPage(pPage);
545 // Inform the parent about change to allow invalidations at
546 // evtl. existing parent visualisations
547 impChildInserted(*pNewObj);
549 pNewObj->SetInserted(true);
550 if (pModel!=NULL) {
551 // TODO: We need a different broadcast here.
552 if (pNewObj->GetPage()!=NULL) {
553 SdrHint aHint(*pNewObj);
554 aHint.SetKind(HINT_OBJINSERTED);
555 pModel->Broadcast(aHint);
557 pModel->SetChanged();
559 SetRectsDirty();
561 return pObj;
564 SdrObject* SdrObjList::NbcSetObjectOrdNum(sal_uIntPtr nOldObjNum, sal_uIntPtr nNewObjNum)
566 if (nOldObjNum >= maList.size() || nNewObjNum >= maList.size())
568 OSL_ASSERT(nOldObjNum<maList.size());
569 OSL_ASSERT(nNewObjNum<maList.size());
570 return NULL;
573 SdrObject* pObj=maList[nOldObjNum];
574 if (nOldObjNum==nNewObjNum) return pObj;
575 DBG_ASSERT(pObj!=NULL,"SdrObjList::NbcSetObjectOrdNum: Object not found.");
576 if (pObj!=NULL) {
577 DBG_ASSERT(pObj->IsInserted(),"SdrObjList::NbcSetObjectOrdNum: ZObjekt does not have status Inserted.");
578 RemoveObjectFromContainer(nOldObjNum);
580 InsertObjectIntoContainer(*pObj,nNewObjNum);
582 // No need to delete visualisation data since same object
583 // gets inserted again. Also a single ActionChanged is enough
584 pObj->ActionChanged();
586 pObj->SetOrdNum(nNewObjNum);
587 bObjOrdNumsDirty=true;
589 return pObj;
592 SdrObject* SdrObjList::SetObjectOrdNum(sal_uIntPtr nOldObjNum, sal_uIntPtr nNewObjNum)
594 if (nOldObjNum >= maList.size() || nNewObjNum >= maList.size())
596 OSL_ASSERT(nOldObjNum<maList.size());
597 OSL_ASSERT(nNewObjNum<maList.size());
598 return NULL;
601 SdrObject* pObj=maList[nOldObjNum];
602 if (nOldObjNum==nNewObjNum) return pObj;
603 DBG_ASSERT(pObj!=NULL,"SdrObjList::SetObjectOrdNum: Object not found.");
604 if (pObj!=NULL) {
605 DBG_ASSERT(pObj->IsInserted(),"SdrObjList::SetObjectOrdNum: ZObjekt does not have status Inserted.");
606 RemoveObjectFromContainer(nOldObjNum);
607 InsertObjectIntoContainer(*pObj,nNewObjNum);
609 // No need to delete visualisation data since same object
610 // gets inserted again. Also a single ActionChanged is enough
611 pObj->ActionChanged();
613 pObj->SetOrdNum(nNewObjNum);
614 bObjOrdNumsDirty=true;
615 if (pModel!=NULL)
617 // TODO: We need a different broadcast here.
618 if (pObj->GetPage()!=NULL) pModel->Broadcast(SdrHint(*pObj));
619 pModel->SetChanged();
622 return pObj;
625 const Rectangle& SdrObjList::GetAllObjSnapRect() const
627 if (bRectsDirty) {
628 ((SdrObjList*)this)->RecalcRects();
629 ((SdrObjList*)this)->bRectsDirty=false;
631 return aSnapRect;
634 const Rectangle& SdrObjList::GetAllObjBoundRect() const
636 // #i106183# for deep group hierarchies like in chart2, the invalidates
637 // through the hierarchy are not correct; use a 2nd hint for the needed
638 // recalculation. Future versions will have no bool flag at all, but
639 // just aOutRect in empty state to represent an invalid state, thus
640 // it's a step in the right direction.
641 if (bRectsDirty || aOutRect.IsEmpty())
643 ((SdrObjList*)this)->RecalcRects();
644 ((SdrObjList*)this)->bRectsDirty=false;
646 return aOutRect;
649 void SdrObjList::NbcReformatAllTextObjects()
651 sal_uIntPtr nAnz=GetObjCount();
652 sal_uIntPtr nNum=0;
654 while (nNum<nAnz)
656 SdrObject* pObj = GetObj(nNum);
658 pObj->NbcReformatText();
659 nAnz=GetObjCount(); // ReformatText may delete an object
660 nNum++;
665 void SdrObjList::ReformatAllTextObjects()
667 NbcReformatAllTextObjects();
670 /** steps over all available objects and reformats all
671 edge objects that are connected to other objects so that
672 they may reposition themselves.
674 void SdrObjList::ReformatAllEdgeObjects()
676 // #i120437# go over whole hierarchy, not only over object level null (seen from grouping)
677 SdrObjListIter aIter(*this, IM_DEEPNOGROUPS);
679 while(aIter.IsMore())
681 SdrEdgeObj* pSdrEdgeObj = dynamic_cast< SdrEdgeObj* >(aIter.Next());
683 if(pSdrEdgeObj)
685 pSdrEdgeObj->Reformat();
690 void SdrObjList::BurnInStyleSheetAttributes()
692 for(sal_uInt32 a(0L); a < GetObjCount(); a++)
694 GetObj(a)->BurnInStyleSheetAttributes();
698 sal_uIntPtr SdrObjList::GetObjCount() const
700 return maList.size();
706 SdrObject* SdrObjList::GetObj(sal_uIntPtr nNum) const
708 if (nNum >= maList.size())
710 OSL_ASSERT(nNum<maList.size());
711 return NULL;
713 else
714 return maList[nNum];
720 bool SdrObjList::IsReadOnly() const
722 bool bRet = false;
723 if (pPage!=NULL && pPage!=this) bRet=pPage->IsReadOnly();
724 return bRet;
727 sal_uIntPtr SdrObjList::CountAllObjects() const
729 sal_uIntPtr nCnt=GetObjCount();
730 sal_uIntPtr nAnz=nCnt;
731 for (sal_uInt16 nNum=0; nNum<nAnz; nNum++) {
732 SdrObjList* pSubOL=GetObj(nNum)->GetSubList();
733 if (pSubOL!=NULL) {
734 nCnt+=pSubOL->CountAllObjects();
737 return nCnt;
740 void SdrObjList::ForceSwapInObjects() const
742 sal_uIntPtr nObjAnz=GetObjCount();
743 for (sal_uIntPtr nObjNum=nObjAnz; nObjNum>0;) {
744 SdrObject* pObj=GetObj(--nObjNum);
745 SdrGrafObj* pGrafObj=PTR_CAST(SdrGrafObj,pObj);
746 if (pGrafObj!=NULL) {
747 pGrafObj->ForceSwapIn();
749 SdrObjList* pOL=pObj->GetSubList();
750 if (pOL!=NULL) {
751 pOL->ForceSwapInObjects();
756 void SdrObjList::ForceSwapOutObjects() const
758 sal_uIntPtr nObjAnz=GetObjCount();
759 for (sal_uIntPtr nObjNum=nObjAnz; nObjNum>0;) {
760 SdrObject* pObj=GetObj(--nObjNum);
761 SdrGrafObj* pGrafObj=PTR_CAST(SdrGrafObj,pObj);
762 if (pGrafObj!=NULL) {
763 pGrafObj->ForceSwapOut();
765 SdrObjList* pOL=pObj->GetSubList();
766 if (pOL!=NULL) {
767 pOL->ForceSwapOutObjects();
772 void SdrObjList::FlattenGroups()
774 sal_Int32 nObj = GetObjCount();
775 sal_Int32 i;
776 for( i=nObj-1; i>=0; --i)
777 UnGroupObj(i);
780 void SdrObjList::UnGroupObj( sal_uIntPtr nObjNum )
782 // if the given object is no group, this method is a noop
783 SdrObject* pUngroupObj = GetObj( nObjNum );
784 if( pUngroupObj )
786 SdrObjList* pSrcLst = pUngroupObj->GetSubList();
787 if( pUngroupObj->ISA( SdrObjGroup ) && pSrcLst )
789 SdrObjGroup* pUngroupGroup = static_cast< SdrObjGroup* > (pUngroupObj);
791 // ungroup recursively (has to be head recursion,
792 // otherwise our indices will get trashed when doing it in
793 // the loop)
794 pSrcLst->FlattenGroups();
796 // the position at which we insert the members of rUngroupGroup
797 sal_Int32 nInsertPos( pUngroupGroup->GetOrdNum() );
799 SdrObject* pObj;
800 sal_Int32 i, nAnz = pSrcLst->GetObjCount();
801 for( i=0; i<nAnz; ++i )
803 pObj = pSrcLst->RemoveObject(0);
804 SdrInsertReason aReason(SDRREASON_VIEWCALL, pUngroupGroup);
805 InsertObject(pObj, nInsertPos, &aReason);
806 ++nInsertPos;
809 RemoveObject(nInsertPos);
812 #ifdef DBG_UTIL
813 else
814 OSL_FAIL("SdrObjList::UnGroupObj: object index invalid");
815 #endif
821 bool SdrObjList::HasObjectNavigationOrder (void) const
823 return mpNavigationOrder.get() != NULL;
829 void SdrObjList::SetObjectNavigationPosition (
830 SdrObject& rObject,
831 const sal_uInt32 nNewPosition)
833 // When the navigation order container has not yet been created then
834 // create one now. It is initialized with the z-order taken from
835 // maList.
836 if (mpNavigationOrder.get() == NULL)
838 mpNavigationOrder.reset(new WeakSdrObjectContainerType(maList.size()));
839 ::std::copy(
840 maList.begin(),
841 maList.end(),
842 mpNavigationOrder->begin());
844 OSL_ASSERT(mpNavigationOrder.get()!=NULL);
845 OSL_ASSERT( mpNavigationOrder->size() == maList.size());
847 SdrObjectWeakRef aReference (&rObject);
849 // Look up the object whose navigation position is to be changed.
850 WeakSdrObjectContainerType::iterator iObject (::std::find(
851 mpNavigationOrder->begin(),
852 mpNavigationOrder->end(),
853 aReference));
854 if (iObject == mpNavigationOrder->end())
856 // The given object is not a member of the navigation order.
857 return;
860 // Move the object to its new position.
861 const sal_uInt32 nOldPosition = ::std::distance(mpNavigationOrder->begin(), iObject);
862 if (nOldPosition != nNewPosition)
864 mpNavigationOrder->erase(iObject);
865 sal_uInt32 nInsertPosition (nNewPosition);
866 // Adapt insertion position for the just erased object.
867 if (nNewPosition >= nOldPosition)
868 nInsertPosition -= 1;
869 if (nInsertPosition >= mpNavigationOrder->size())
870 mpNavigationOrder->push_back(aReference);
871 else
872 mpNavigationOrder->insert(mpNavigationOrder->begin()+nInsertPosition, aReference);
874 mbIsNavigationOrderDirty = true;
876 // The navigation order is written out to file so mark the model as modified.
877 if (pModel != NULL)
878 pModel->SetChanged();
885 SdrObject* SdrObjList::GetObjectForNavigationPosition (const sal_uInt32 nNavigationPosition) const
887 if (HasObjectNavigationOrder())
889 // There is a user defined navigation order. Make sure the object
890 // index is correct and look up the object in mpNavigationOrder.
891 if (nNavigationPosition >= mpNavigationOrder->size())
893 OSL_ASSERT(nNavigationPosition < mpNavigationOrder->size());
895 else
896 return (*mpNavigationOrder)[nNavigationPosition].get();
898 else
900 // There is no user defined navigation order. Use the z-order
901 // instead.
902 if (nNavigationPosition >= maList.size())
904 OSL_ASSERT(nNavigationPosition < maList.size());
906 else
907 return maList[nNavigationPosition];
909 return NULL;
915 void SdrObjList::ClearObjectNavigationOrder (void)
917 mpNavigationOrder.reset();
918 mbIsNavigationOrderDirty = true;
924 bool SdrObjList::RecalcNavigationPositions (void)
926 if (mbIsNavigationOrderDirty)
928 if (mpNavigationOrder.get() != NULL)
930 mbIsNavigationOrderDirty = false;
932 WeakSdrObjectContainerType::iterator iObject;
933 WeakSdrObjectContainerType::const_iterator iEnd (mpNavigationOrder->end());
934 sal_uInt32 nIndex (0);
935 for (iObject=mpNavigationOrder->begin(); iObject!=iEnd; ++iObject,++nIndex)
936 (*iObject)->SetNavigationPosition(nIndex);
940 return mpNavigationOrder.get() != NULL;
946 void SdrObjList::SetNavigationOrder (const uno::Reference<container::XIndexAccess>& rxOrder)
948 if (rxOrder.is())
950 const sal_Int32 nCount = rxOrder->getCount();
951 if ((sal_uInt32)nCount != maList.size())
952 return;
954 if (mpNavigationOrder.get() == NULL)
955 mpNavigationOrder.reset(new WeakSdrObjectContainerType(nCount));
957 for (sal_Int32 nIndex=0; nIndex<nCount; ++nIndex)
959 uno::Reference<uno::XInterface> xShape (rxOrder->getByIndex(nIndex), uno::UNO_QUERY);
960 SdrObject* pObject = SdrObject::getSdrObjectFromXShape(xShape);
961 if (pObject == NULL)
962 break;
963 (*mpNavigationOrder)[nIndex] = pObject;
966 mbIsNavigationOrderDirty = true;
968 else
969 ClearObjectNavigationOrder();
975 void SdrObjList::InsertObjectIntoContainer (
976 SdrObject& rObject,
977 const sal_uInt32 nInsertPosition)
979 OSL_ASSERT(nInsertPosition<=maList.size());
981 // Update the navigation positions.
982 if (HasObjectNavigationOrder())
984 // The new object does not have a user defined position so append it
985 // to the list.
986 rObject.SetNavigationPosition(mpNavigationOrder->size());
987 mpNavigationOrder->push_back(&rObject);
990 // Insert object into object list. Because the insert() method requires
991 // a valid iterator as insertion position, we have to use push_back() to
992 // insert at the end of the list.
993 if (nInsertPosition >= maList.size())
994 maList.push_back(&rObject);
995 else
996 maList.insert(maList.begin()+nInsertPosition, &rObject);
997 bObjOrdNumsDirty=true;
1003 void SdrObjList::ReplaceObjectInContainer (
1004 SdrObject& rNewObject,
1005 const sal_uInt32 nObjectPosition)
1007 if (nObjectPosition >= maList.size())
1009 OSL_ASSERT(nObjectPosition<maList.size());
1010 return;
1013 // Update the navigation positions.
1014 if (HasObjectNavigationOrder())
1016 // A user defined position of the object that is to be replaced is
1017 // not transferred to the new object so erase the former and append
1018 // the later object from/to the navigation order.
1019 OSL_ASSERT(nObjectPosition < maList.size());
1020 SdrObjectWeakRef aReference (maList[nObjectPosition]);
1021 WeakSdrObjectContainerType::iterator iObject (::std::find(
1022 mpNavigationOrder->begin(),
1023 mpNavigationOrder->end(),
1024 aReference));
1025 if (iObject != mpNavigationOrder->end())
1026 mpNavigationOrder->erase(iObject);
1028 mpNavigationOrder->push_back(&rNewObject);
1030 mbIsNavigationOrderDirty = true;
1033 maList[nObjectPosition] = &rNewObject;
1034 bObjOrdNumsDirty=true;
1040 void SdrObjList::RemoveObjectFromContainer (
1041 const sal_uInt32 nObjectPosition)
1043 if (nObjectPosition >= maList.size())
1045 OSL_ASSERT(nObjectPosition<maList.size());
1046 return;
1049 // Update the navigation positions.
1050 if (HasObjectNavigationOrder())
1052 SdrObjectWeakRef aReference (maList[nObjectPosition]);
1053 WeakSdrObjectContainerType::iterator iObject (::std::find(
1054 mpNavigationOrder->begin(),
1055 mpNavigationOrder->end(),
1056 aReference));
1057 if (iObject != mpNavigationOrder->end())
1058 mpNavigationOrder->erase(iObject);
1059 mbIsNavigationOrderDirty = true;
1062 maList.erase(maList.begin()+nObjectPosition);
1063 bObjOrdNumsDirty=true;
1071 void SdrPageGridFrameList::Clear()
1073 sal_uInt16 nAnz=GetCount();
1074 for (sal_uInt16 i=0; i<nAnz; i++) {
1075 delete GetObject(i);
1077 aList.clear();
1081 // PageUser section
1083 void SdrPage::AddPageUser(sdr::PageUser& rNewUser)
1085 maPageUsers.push_back(&rNewUser);
1088 void SdrPage::RemovePageUser(sdr::PageUser& rOldUser)
1090 const ::sdr::PageUserVector::iterator aFindResult = ::std::find(maPageUsers.begin(), maPageUsers.end(), &rOldUser);
1091 if(aFindResult != maPageUsers.end())
1093 maPageUsers.erase(aFindResult);
1098 // DrawContact section
1100 sdr::contact::ViewContact* SdrPage::CreateObjectSpecificViewContact()
1102 return new sdr::contact::ViewContactOfSdrPage(*this);
1105 sdr::contact::ViewContact& SdrPage::GetViewContact() const
1107 if(!mpViewContact)
1109 const_cast< SdrPage* >(this)->mpViewContact =
1110 const_cast< SdrPage* >(this)->CreateObjectSpecificViewContact();
1113 return *mpViewContact;
1118 void SdrPageProperties::ImpRemoveStyleSheet()
1120 if(mpStyleSheet)
1122 EndListening(*mpStyleSheet);
1123 mpProperties->SetParent(0);
1124 mpStyleSheet = 0;
1128 void SdrPageProperties::ImpAddStyleSheet(SfxStyleSheet& rNewStyleSheet)
1130 if(mpStyleSheet != &rNewStyleSheet)
1132 ImpRemoveStyleSheet();
1133 mpStyleSheet = &rNewStyleSheet;
1134 StartListening(rNewStyleSheet);
1135 mpProperties->SetParent(&rNewStyleSheet.GetItemSet());
1139 void ImpPageChange(SdrPage& rSdrPage)
1141 rSdrPage.ActionChanged();
1143 if(rSdrPage.GetModel())
1145 rSdrPage.GetModel()->SetChanged(true);
1146 SdrHint aHint(HINT_PAGEORDERCHG);
1147 aHint.SetPage(&rSdrPage);
1148 rSdrPage.GetModel()->Broadcast(aHint);
1152 SdrPageProperties::SdrPageProperties(SdrPage& rSdrPage)
1153 : SfxListener(),
1154 mpSdrPage(&rSdrPage),
1155 mpStyleSheet(0),
1156 mpProperties(new SfxItemSet(mpSdrPage->GetModel()->GetItemPool(), XATTR_FILL_FIRST, XATTR_FILL_LAST))
1158 if(!rSdrPage.IsMasterPage())
1160 mpProperties->Put(XFillStyleItem(XFILL_NONE));
1164 SdrPageProperties::~SdrPageProperties()
1166 ImpRemoveStyleSheet();
1167 delete mpProperties;
1170 void SdrPageProperties::Notify(SfxBroadcaster& /*rBC*/, const SfxHint& rHint)
1172 const SfxSimpleHint* pSimpleHint = dynamic_cast< const SfxSimpleHint* >(&rHint);
1174 if(pSimpleHint)
1176 switch(pSimpleHint->GetId())
1178 case SFX_HINT_DATACHANGED :
1180 // notify change, broadcast
1181 ImpPageChange(*mpSdrPage);
1182 break;
1184 case SFX_HINT_DYING :
1186 // Style needs to be forgotten
1187 ImpRemoveStyleSheet();
1188 break;
1194 bool SdrPageProperties::isUsedByModel() const
1196 assert(mpSdrPage);
1197 return mpSdrPage->IsInserted();
1200 const SfxItemSet& SdrPageProperties::GetItemSet() const
1202 return *mpProperties;
1205 void SdrPageProperties::PutItemSet(const SfxItemSet& rSet)
1207 OSL_ENSURE(!mpSdrPage->IsMasterPage(), "Item set at MasterPage Attributes (!)");
1208 mpProperties->Put(rSet);
1209 ImpPageChange(*mpSdrPage);
1212 void SdrPageProperties::PutItem(const SfxPoolItem& rItem)
1214 OSL_ENSURE(!mpSdrPage->IsMasterPage(), "Item set at MasterPage Attributes (!)");
1215 mpProperties->Put(rItem);
1216 ImpPageChange(*mpSdrPage);
1219 void SdrPageProperties::ClearItem(const sal_uInt16 nWhich)
1221 mpProperties->ClearItem(nWhich);
1222 ImpPageChange(*mpSdrPage);
1225 void SdrPageProperties::SetStyleSheet(SfxStyleSheet* pStyleSheet)
1227 if(pStyleSheet)
1229 ImpAddStyleSheet(*pStyleSheet);
1231 else
1233 ImpRemoveStyleSheet();
1236 ImpPageChange(*mpSdrPage);
1239 SfxStyleSheet* SdrPageProperties::GetStyleSheet() const
1241 return mpStyleSheet;
1246 TYPEINIT1(SdrPage,SdrObjList);
1247 SdrPage::SdrPage(SdrModel& rNewModel, bool bMasterPage)
1248 : SdrObjList(&rNewModel, this),
1249 mpViewContact(0L),
1250 nWdt(10L),
1251 nHgt(10L),
1252 nBordLft(0L),
1253 nBordUpp(0L),
1254 nBordRgt(0L),
1255 nBordLwr(0L),
1256 pLayerAdmin(new SdrLayerAdmin(&rNewModel.GetLayerAdmin())),
1257 mpSdrPageProperties(0),
1258 mpMasterPageDescriptor(0L),
1259 nPageNum(0L),
1260 mbMaster(bMasterPage),
1261 mbInserted(false),
1262 mbObjectsNotPersistent(false),
1263 mbSwappingLocked(false),
1264 mbPageBorderOnlyLeftRight(false)
1266 aPrefVisiLayers.SetAll();
1267 eListKind = (bMasterPage) ? SDROBJLIST_MASTERPAGE : SDROBJLIST_DRAWPAGE;
1269 mpSdrPageProperties = new SdrPageProperties(*this);
1272 SdrPage::SdrPage(const SdrPage& rSrcPage)
1273 : SdrObjList(rSrcPage.pModel, this),
1274 tools::WeakBase< SdrPage >(),
1275 mpViewContact(0L),
1276 nWdt(rSrcPage.nWdt),
1277 nHgt(rSrcPage.nHgt),
1278 nBordLft(rSrcPage.nBordLft),
1279 nBordUpp(rSrcPage.nBordUpp),
1280 nBordRgt(rSrcPage.nBordRgt),
1281 nBordLwr(rSrcPage.nBordLwr),
1282 pLayerAdmin(new SdrLayerAdmin(rSrcPage.pModel->GetLayerAdmin())),
1283 mpSdrPageProperties(0),
1284 mpMasterPageDescriptor(0L),
1285 nPageNum(rSrcPage.nPageNum),
1286 mbMaster(rSrcPage.mbMaster),
1287 mbInserted(false),
1288 mbObjectsNotPersistent(rSrcPage.mbObjectsNotPersistent),
1289 mbSwappingLocked(rSrcPage.mbSwappingLocked),
1290 mbPageBorderOnlyLeftRight(rSrcPage.mbPageBorderOnlyLeftRight)
1292 aPrefVisiLayers.SetAll();
1293 eListKind = (mbMaster) ? SDROBJLIST_MASTERPAGE : SDROBJLIST_DRAWPAGE;
1295 // copy things from source
1296 // Warning: this leads to slicing (see issue 93186) and has to be
1297 // removed as soon as possible.
1298 *this = rSrcPage;
1299 OSL_ENSURE(mpSdrPageProperties,
1300 "SdrPage::SdrPage: operator= did not create needed SdrPageProperties (!)");
1302 // be careful and correct eListKind, a member of SdrObjList which
1303 // will be changed by the SdrOIbjList::operator= before...
1304 eListKind = (mbMaster) ? SDROBJLIST_MASTERPAGE : SDROBJLIST_DRAWPAGE;
1306 // The previous assignment to *this may have resulted in a call to
1307 // createUnoPage at a partially initialized (sliced) SdrPage object.
1308 // Due to the vtable being not yet fully set-up at this stage,
1309 // createUnoPage() may have been called at the wrong class.
1310 // To force a call to the right createUnoPage() at a later time when the
1311 // new object is full constructed mxUnoPage is disposed now.
1312 uno::Reference<lang::XComponent> xComponent (mxUnoPage, uno::UNO_QUERY);
1313 if (xComponent.is())
1315 mxUnoPage = NULL;
1316 xComponent->dispose();
1320 SdrPage::~SdrPage()
1322 if( mxUnoPage.is() ) try
1324 uno::Reference< lang::XComponent > xPageComponent( mxUnoPage, uno::UNO_QUERY_THROW );
1325 mxUnoPage.clear();
1326 xPageComponent->dispose();
1328 catch( const uno::Exception& )
1330 DBG_UNHANDLED_EXCEPTION();
1333 // tell all the registered PageUsers that the page is in destruction
1334 // This causes some (all?) PageUsers to remove themselves from the list
1335 // of page users. Therefore we have to use a copy of the list for the
1336 // iteration.
1337 ::sdr::PageUserVector aListCopy (maPageUsers.begin(), maPageUsers.end());
1338 for(::sdr::PageUserVector::iterator aIterator = aListCopy.begin(); aIterator != aListCopy.end(); ++aIterator)
1340 sdr::PageUser* pPageUser = *aIterator;
1341 DBG_ASSERT(pPageUser, "SdrPage::~SdrPage: corrupt PageUser list (!)");
1342 pPageUser->PageInDestruction(*this);
1345 // Clear the vector. This means that user do not need to call RemovePageUser()
1346 // when they get called from PageInDestruction().
1347 maPageUsers.clear();
1349 delete pLayerAdmin;
1351 TRG_ClearMasterPage();
1353 if(mpViewContact)
1355 delete mpViewContact;
1356 mpViewContact = 0L;
1360 delete mpSdrPageProperties;
1361 mpSdrPageProperties = 0;
1366 SdrPage& SdrPage::operator=(const SdrPage& rSrcPage)
1368 if( this == &rSrcPage )
1369 return *this;
1370 if(mpViewContact)
1372 delete mpViewContact;
1373 mpViewContact = 0L;
1376 // Joe also sets some parameters for the class this one
1377 // is derived from. SdrObjList does the same bad handling of
1378 // copy constructor and operator=, so i better let it stand here.
1379 pPage = this;
1381 // copy all the local parameters to make this instance
1382 // a valid copy of source page before copying and inserting
1383 // the contained objects
1384 mbMaster = rSrcPage.mbMaster;
1385 mbSwappingLocked = rSrcPage.mbSwappingLocked;
1386 mbPageBorderOnlyLeftRight = rSrcPage.mbPageBorderOnlyLeftRight;
1387 aPrefVisiLayers = rSrcPage.aPrefVisiLayers;
1388 nWdt = rSrcPage.nWdt;
1389 nHgt = rSrcPage.nHgt;
1390 nBordLft = rSrcPage.nBordLft;
1391 nBordUpp = rSrcPage.nBordUpp;
1392 nBordRgt = rSrcPage.nBordRgt;
1393 nBordLwr = rSrcPage.nBordLwr;
1394 nPageNum = rSrcPage.nPageNum;
1396 if(rSrcPage.TRG_HasMasterPage())
1398 TRG_SetMasterPage(rSrcPage.TRG_GetMasterPage());
1399 TRG_SetMasterPageVisibleLayers(rSrcPage.TRG_GetMasterPageVisibleLayers());
1401 else
1403 TRG_ClearMasterPage();
1406 mbObjectsNotPersistent = rSrcPage.mbObjectsNotPersistent;
1409 // #i111122# delete SdrPageProperties when model is different
1410 if(mpSdrPageProperties && GetModel() != rSrcPage.GetModel())
1412 delete mpSdrPageProperties;
1413 mpSdrPageProperties = 0;
1416 if(!mpSdrPageProperties)
1418 mpSdrPageProperties = new SdrPageProperties(*this);
1420 else
1422 mpSdrPageProperties->ClearItem(0);
1425 if(!IsMasterPage())
1427 mpSdrPageProperties->PutItemSet(rSrcPage.getSdrPageProperties().GetItemSet());
1430 mpSdrPageProperties->SetStyleSheet(rSrcPage.getSdrPageProperties().GetStyleSheet());
1433 // Now copy the contained objects (by cloning them)
1434 SdrObjList::operator=(rSrcPage);
1435 return *this;
1438 SdrPage* SdrPage::Clone() const
1440 return Clone(NULL);
1443 SdrPage* SdrPage::Clone(SdrModel* pNewModel) const
1445 if (pNewModel==NULL) pNewModel=pModel;
1446 SdrPage* pPage2=new SdrPage(*pNewModel);
1447 *pPage2=*this;
1448 return pPage2;
1451 void SdrPage::SetSize(const Size& aSiz)
1453 bool bChanged(false);
1455 if(aSiz.Width() != nWdt)
1457 nWdt = aSiz.Width();
1458 bChanged = true;
1461 if(aSiz.Height() != nHgt)
1463 nHgt = aSiz.Height();
1464 bChanged = true;
1467 if(bChanged)
1469 SetChanged();
1473 Size SdrPage::GetSize() const
1475 return Size(nWdt,nHgt);
1478 sal_Int32 SdrPage::GetWdt() const
1480 return nWdt;
1483 void SdrPage::SetOrientation(Orientation eOri)
1485 // square: handle like portrait format
1486 Size aSiz(GetSize());
1487 if (aSiz.Width()!=aSiz.Height()) {
1488 if ((eOri==ORIENTATION_PORTRAIT) == (aSiz.Width()>aSiz.Height())) {
1489 SetSize(Size(aSiz.Height(),aSiz.Width()));
1494 Orientation SdrPage::GetOrientation() const
1496 // square: handle like portrait format
1497 Orientation eRet=ORIENTATION_PORTRAIT;
1498 Size aSiz(GetSize());
1499 if (aSiz.Width()>aSiz.Height()) eRet=ORIENTATION_LANDSCAPE;
1500 return eRet;
1503 sal_Int32 SdrPage::GetHgt() const
1505 return nHgt;
1508 void SdrPage::SetBorder(sal_Int32 nLft, sal_Int32 nUpp, sal_Int32 nRgt, sal_Int32 nLwr)
1510 bool bChanged(false);
1512 if(nBordLft != nLft)
1514 nBordLft = nLft;
1515 bChanged = true;
1518 if(nBordUpp != nUpp)
1520 nBordUpp = nUpp;
1521 bChanged = true;
1524 if(nBordRgt != nRgt)
1526 nBordRgt = nRgt;
1527 bChanged = true;
1530 if(nBordLwr != nLwr)
1532 nBordLwr = nLwr;
1533 bChanged = true;
1536 if(bChanged)
1538 SetChanged();
1542 void SdrPage::SetLftBorder(sal_Int32 nBorder)
1544 if(nBordLft != nBorder)
1546 nBordLft = nBorder;
1547 SetChanged();
1551 void SdrPage::SetUppBorder(sal_Int32 nBorder)
1553 if(nBordUpp != nBorder)
1555 nBordUpp = nBorder;
1556 SetChanged();
1560 void SdrPage::SetRgtBorder(sal_Int32 nBorder)
1562 if(nBordRgt != nBorder)
1564 nBordRgt=nBorder;
1565 SetChanged();
1569 void SdrPage::SetLwrBorder(sal_Int32 nBorder)
1571 if(nBordLwr != nBorder)
1573 nBordLwr=nBorder;
1574 SetChanged();
1578 sal_Int32 SdrPage::GetLftBorder() const
1580 return nBordLft;
1583 sal_Int32 SdrPage::GetUppBorder() const
1585 return nBordUpp;
1588 sal_Int32 SdrPage::GetRgtBorder() const
1590 return nBordRgt;
1593 sal_Int32 SdrPage::GetLwrBorder() const
1595 return nBordLwr;
1598 void SdrPage::SetModel(SdrModel* pNewModel)
1600 SdrModel* pOldModel=pModel;
1601 SdrObjList::SetModel(pNewModel);
1602 if (pNewModel!=pOldModel)
1604 if (pNewModel!=NULL) {
1605 pLayerAdmin->SetParent(&pNewModel->GetLayerAdmin());
1606 } else {
1607 pLayerAdmin->SetParent(NULL);
1609 pLayerAdmin->SetModel(pNewModel);
1611 // create new SdrPageProperties with new model (due to SfxItemSet there)
1612 // and copy ItemSet and StyleSheet
1613 SdrPageProperties *pNew = new SdrPageProperties(*this);
1615 if(!IsMasterPage())
1617 pNew->PutItemSet(getSdrPageProperties().GetItemSet());
1620 pNew->SetStyleSheet(getSdrPageProperties().GetStyleSheet());
1622 delete mpSdrPageProperties;
1623 mpSdrPageProperties = pNew;
1626 // update listeners at possible API wrapper object
1627 if( pOldModel != pNewModel )
1629 if( mxUnoPage.is() )
1631 SvxDrawPage* pPage2 = SvxDrawPage::getImplementation( mxUnoPage );
1632 if( pPage2 )
1633 pPage2->ChangeModel( pNewModel );
1640 // #i68775# React on PageNum changes (from Model in most cases)
1641 void SdrPage::SetPageNum(sal_uInt16 nNew)
1643 if(nNew != nPageNum)
1645 // change
1646 nPageNum = nNew;
1648 // notify visualisations, also notifies e.g. buffered MasterPages
1649 ActionChanged();
1653 sal_uInt16 SdrPage::GetPageNum() const
1655 if (!mbInserted)
1656 return 0;
1658 if (mbMaster) {
1659 if (pModel && pModel->IsMPgNumsDirty())
1660 ((SdrModel*)pModel)->RecalcPageNums(true);
1661 } else {
1662 if (pModel && pModel->IsPagNumsDirty())
1663 ((SdrModel*)pModel)->RecalcPageNums(false);
1665 return nPageNum;
1668 void SdrPage::SetChanged()
1670 // For test purposes, use the new ViewContact for change
1671 // notification now.
1672 ActionChanged();
1674 if( pModel )
1676 pModel->SetChanged();
1681 // MasterPage interface
1683 void SdrPage::TRG_SetMasterPage(SdrPage& rNew)
1685 if(mpMasterPageDescriptor && &(mpMasterPageDescriptor->GetUsedPage()) == &rNew)
1686 return;
1688 if(mpMasterPageDescriptor)
1689 TRG_ClearMasterPage();
1691 mpMasterPageDescriptor = new ::sdr::MasterPageDescriptor(*this, rNew);
1692 GetViewContact().ActionChanged();
1695 void SdrPage::TRG_ClearMasterPage()
1697 if(mpMasterPageDescriptor)
1699 SetChanged();
1701 // the flushViewObjectContacts() will do needed invalidates by deleting the involved VOCs
1702 mpMasterPageDescriptor->GetUsedPage().GetViewContact().flushViewObjectContacts(true);
1704 delete mpMasterPageDescriptor;
1705 mpMasterPageDescriptor = 0L;
1709 SdrPage& SdrPage::TRG_GetMasterPage() const
1711 DBG_ASSERT(mpMasterPageDescriptor != 0L, "TRG_GetMasterPage(): No MasterPage available. Use TRG_HasMasterPage() before access (!)");
1712 return mpMasterPageDescriptor->GetUsedPage();
1715 const SetOfByte& SdrPage::TRG_GetMasterPageVisibleLayers() const
1717 DBG_ASSERT(mpMasterPageDescriptor != 0L, "TRG_GetMasterPageVisibleLayers(): No MasterPage available. Use TRG_HasMasterPage() before access (!)");
1718 return mpMasterPageDescriptor->GetVisibleLayers();
1721 void SdrPage::TRG_SetMasterPageVisibleLayers(const SetOfByte& rNew)
1723 DBG_ASSERT(mpMasterPageDescriptor != 0L, "TRG_SetMasterPageVisibleLayers(): No MasterPage available. Use TRG_HasMasterPage() before access (!)");
1724 mpMasterPageDescriptor->SetVisibleLayers(rNew);
1727 sdr::contact::ViewContact& SdrPage::TRG_GetMasterPageDescriptorViewContact() const
1729 DBG_ASSERT(mpMasterPageDescriptor != 0L, "TRG_GetMasterPageDescriptorViewContact(): No MasterPage available. Use TRG_HasMasterPage() before access (!)");
1730 return mpMasterPageDescriptor->GetViewContact();
1733 // used from SdrModel::RemoveMasterPage
1734 void SdrPage::TRG_ImpMasterPageRemoved(const SdrPage& rRemovedPage)
1736 if(TRG_HasMasterPage())
1738 if(&TRG_GetMasterPage() == &rRemovedPage)
1740 TRG_ClearMasterPage();
1745 const SdrPageGridFrameList* SdrPage::GetGridFrameList(const SdrPageView* /*pPV*/, const Rectangle* /*pRect*/) const
1747 return NULL;
1750 OUString SdrPage::GetLayoutName() const
1752 return OUString();
1755 void SdrPage::SetInserted( bool bIns )
1757 if( (bool) mbInserted != bIns )
1759 mbInserted = bIns;
1761 // #i120437# go over whole hierarchy, not only over object level null (seen from grouping)
1762 SdrObjListIter aIter(*this, IM_DEEPNOGROUPS);
1764 while ( aIter.IsMore() )
1766 SdrObject* pObj = aIter.Next();
1767 if ( pObj->ISA(SdrOle2Obj) )
1769 if( mbInserted )
1770 ( (SdrOle2Obj*) pObj)->Connect();
1771 else
1772 ( (SdrOle2Obj*) pObj)->Disconnect();
1778 void SdrPage::SetUnoPage(uno::Reference<drawing::XDrawPage> const& xNewPage)
1780 mxUnoPage = xNewPage;
1783 uno::Reference< uno::XInterface > SdrPage::getUnoPage()
1785 if( !mxUnoPage.is() )
1787 // create one
1788 mxUnoPage = createUnoPage();
1791 return mxUnoPage;
1794 uno::Reference< uno::XInterface > SdrPage::createUnoPage()
1796 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xInt =
1797 static_cast<cppu::OWeakObject*>( new SvxFmDrawPage( this ) );
1798 return xInt;
1801 SfxStyleSheet* SdrPage::GetTextStyleSheetForObject( SdrObject* pObj ) const
1803 return pObj->GetStyleSheet();
1806 /** returns an averaged background color of this page */
1807 // #i75566# GetBackgroundColor -> GetPageBackgroundColor and bScreenDisplay hint value
1808 Color SdrPage::GetPageBackgroundColor( SdrPageView* pView, bool bScreenDisplay ) const
1810 Color aColor;
1812 if(bScreenDisplay && (!pView || pView->GetApplicationDocumentColor() == COL_AUTO))
1814 svtools::ColorConfig aColorConfig;
1815 aColor = aColorConfig.GetColorValue( svtools::DOCCOLOR ).nColor;
1817 else
1819 aColor = pView->GetApplicationDocumentColor();
1822 const SfxItemSet* pBackgroundFill = &getSdrPageProperties().GetItemSet();
1824 if(!IsMasterPage() && TRG_HasMasterPage())
1826 if(XFILL_NONE == ((const XFillStyleItem&)pBackgroundFill->Get(XATTR_FILLSTYLE)).GetValue())
1828 pBackgroundFill = &TRG_GetMasterPage().getSdrPageProperties().GetItemSet();
1832 GetDraftFillColor(*pBackgroundFill, aColor);
1834 return aColor;
1837 /** *deprecated, use GetBackgroundColor with SdrPageView */
1838 Color SdrPage::GetPageBackgroundColor() const
1839 // #i75566# GetBackgroundColor -> GetPageBackgroundColor
1841 return GetPageBackgroundColor( NULL, true );
1844 /** this method returns true if the object from the ViewObjectContact should
1845 be visible on this page while rendering.
1846 bEdit selects if visibility test is for an editing view or a final render,
1847 like printing.
1849 bool SdrPage::checkVisibility(
1850 const sdr::contact::ViewObjectContact& /*rOriginal*/,
1851 const sdr::contact::DisplayInfo& /*rDisplayInfo*/,
1852 bool /*bEdit*/)
1854 // this will be handled in the application if needed
1855 return true;
1858 // DrawContact support: Methods for handling Page changes
1859 void SdrPage::ActionChanged() const
1861 // Do necessary ViewContact actions
1862 GetViewContact().ActionChanged();
1864 // #i48535# also handle MasterPage change
1865 if(TRG_HasMasterPage())
1867 TRG_GetMasterPageDescriptorViewContact().ActionChanged();
1872 // sdr::Comment interface
1874 const SdrPageProperties* SdrPage::getCorrectSdrPageProperties() const
1876 if(mpMasterPageDescriptor)
1878 return mpMasterPageDescriptor->getCorrectSdrPageProperties();
1880 else
1882 return &getSdrPageProperties();
1887 // use new redirector instead of pPaintProc
1889 StandardCheckVisisbilityRedirector::StandardCheckVisisbilityRedirector()
1890 : ViewObjectContactRedirector()
1894 StandardCheckVisisbilityRedirector::~StandardCheckVisisbilityRedirector()
1898 drawinglayer::primitive2d::Primitive2DSequence StandardCheckVisisbilityRedirector::createRedirectedPrimitive2DSequence(
1899 const sdr::contact::ViewObjectContact& rOriginal,
1900 const sdr::contact::DisplayInfo& rDisplayInfo)
1902 SdrObject* pObject = rOriginal.GetViewContact().TryToGetSdrObject();
1904 if(pObject)
1906 if(pObject->GetPage())
1908 if(pObject->GetPage()->checkVisibility(rOriginal, rDisplayInfo, false))
1910 return ::sdr::contact::ViewObjectContactRedirector::createRedirectedPrimitive2DSequence(rOriginal, rDisplayInfo);
1914 return drawinglayer::primitive2d::Primitive2DSequence();
1916 else
1918 // not an object, maybe a page
1919 return ::sdr::contact::ViewObjectContactRedirector::createRedirectedPrimitive2DSequence(rOriginal, rDisplayInfo);
1924 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */