Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / svx / source / svdraw / svdpage.cxx
blobcd8ba23e417689db28b9b8c2047b0c1ba8bdedde
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include <svx/svdpage.hxx>
32 // HACK
33 #include <sot/storage.hxx>
34 #include <sot/clsids.hxx>
35 #include <svx/svdview.hxx>
36 #include <string.h>
37 #ifndef _STRING_H
38 #define _STRING_H
39 #endif
40 #include <vcl/svapp.hxx>
42 #include <tools/diagnose_ex.h>
44 #include <svx/svdetc.hxx>
45 #include <svx/svdobj.hxx>
46 #include <svx/svdogrp.hxx>
47 #include <svx/svdograf.hxx> // for SwapInAll()
48 #include <svx/svdoedge.hxx> // for copying the connectors
49 #include <svx/svdoole2.hxx> // special case OLE at SdrExchangeFormat
50 #include "svx/svditer.hxx"
51 #include <svx/svdmodel.hxx>
52 #include <svx/svdlayer.hxx>
53 #include <svx/svdotext.hxx>
54 #include <svx/svdpagv.hxx>
55 #include <svx/svdundo.hxx>
56 #include <svx/fmglob.hxx>
57 #include <svx/polysc3d.hxx>
59 #include <svx/fmdpage.hxx>
61 #include <sfx2/objsh.hxx>
62 #include <vcl/salbtype.hxx> // FRound
63 #include <svx/sdr/contact/viewcontactofsdrpage.hxx>
64 #include <svx/sdr/contact/viewobjectcontact.hxx>
65 #include <svx/sdr/contact/displayinfo.hxx>
66 #include <algorithm>
67 #include <svl/smplhint.hxx>
68 #include <rtl/strbuf.hxx>
70 using namespace ::com::sun::star;
72 class SdrObjList::WeakSdrObjectContainerType
73 : public ::std::vector<SdrObjectWeakRef>
75 public:
76 WeakSdrObjectContainerType (const sal_Int32 nInitialSize)
77 : ::std::vector<SdrObjectWeakRef>(nInitialSize) {};
82 static const sal_Int32 InitialObjectContainerCapacity (64);
83 DBG_NAME(SdrObjList)
85 TYPEINIT0(SdrObjList);
87 SdrObjList::SdrObjList(SdrModel* pNewModel, SdrPage* pNewPage, SdrObjList* pNewUpList):
88 maList(),
89 mpNavigationOrder(),
90 mbIsNavigationOrderDirty(false)
92 DBG_CTOR(SdrObjList,NULL);
93 maList.reserve(InitialObjectContainerCapacity);
94 pModel=pNewModel;
95 pPage=pNewPage;
96 pUpList=pNewUpList;
97 bObjOrdNumsDirty=sal_False;
98 bRectsDirty=sal_False;
99 pOwnerObj=NULL;
100 eListKind=SDROBJLIST_UNKNOWN;
103 SdrObjList::SdrObjList(const SdrObjList& rSrcList):
104 maList(),
105 mpNavigationOrder(),
106 mbIsNavigationOrderDirty(false)
108 DBG_CTOR(SdrObjList,NULL);
109 maList.reserve(InitialObjectContainerCapacity);
110 pModel=NULL;
111 pPage=NULL;
112 pUpList=NULL;
113 bObjOrdNumsDirty=sal_False;
114 bRectsDirty=sal_False;
115 pOwnerObj=NULL;
116 eListKind=SDROBJLIST_UNKNOWN;
117 *this=rSrcList;
120 SdrObjList::~SdrObjList()
122 DBG_DTOR(SdrObjList,NULL);
124 // To avoid that the Clear() method will broadcast changes when in destruction
125 // which would call virtual methos (not allowed in destructor), the model is set
126 // to NULL here.
127 pModel = 0L;
129 Clear(); // delete contents of container
132 void SdrObjList::operator=(const SdrObjList& rSrcList)
134 Clear();
135 eListKind=rSrcList.eListKind;
136 CopyObjects(rSrcList);
139 void SdrObjList::CopyObjects(const SdrObjList& rSrcList)
141 Clear();
142 bObjOrdNumsDirty=sal_False;
143 bRectsDirty =sal_False;
144 sal_uIntPtr nCloneErrCnt=0;
145 sal_uIntPtr nAnz=rSrcList.GetObjCount();
146 SdrInsertReason aReason(SDRREASON_COPY);
147 sal_uIntPtr no;
148 for (no=0; no<nAnz; no++) {
149 SdrObject* pSO=rSrcList.GetObj(no);
151 SdrObject* pDO = pSO->Clone();
153 if (pDO!=NULL) {
154 pDO->SetModel(pModel);
155 pDO->SetPage(pPage);
156 NbcInsertObject(pDO,CONTAINER_APPEND,&aReason);
157 } else {
158 nCloneErrCnt++;
162 // and now for the Connectors
163 // The new objects would be shown in the rSrcList
164 // and then the object connections are made.
165 // Similar implementation are setup as the following:
166 // void SdrObjList::CopyObjects(const SdrObjList& rSrcList)
167 // SdrModel* SdrExchangeView::GetMarkedObjModel() const
168 // BOOL SdrExchangeView::Paste(const SdrModel& rMod,...)
169 // void SdrEditView::CopyMarked()
170 if (nCloneErrCnt==0) {
171 for (no=0; no<nAnz; no++) {
172 const SdrObject* pSrcOb=rSrcList.GetObj(no);
173 SdrEdgeObj* pSrcEdge=PTR_CAST(SdrEdgeObj,pSrcOb);
174 if (pSrcEdge!=NULL) {
175 SdrObject* pSrcNode1=pSrcEdge->GetConnectedNode(sal_True);
176 SdrObject* pSrcNode2=pSrcEdge->GetConnectedNode(sal_False);
177 if (pSrcNode1!=NULL && pSrcNode1->GetObjList()!=pSrcEdge->GetObjList()) pSrcNode1=NULL; // can't do this
178 if (pSrcNode2!=NULL && pSrcNode2->GetObjList()!=pSrcEdge->GetObjList()) pSrcNode2=NULL; // across all lists (yet)
179 if (pSrcNode1!=NULL || pSrcNode2!=NULL) {
180 SdrObject* pEdgeObjTmp=GetObj(no);
181 SdrEdgeObj* pDstEdge=PTR_CAST(SdrEdgeObj,pEdgeObjTmp);
182 if (pDstEdge!=NULL) {
183 if (pSrcNode1!=NULL) {
184 sal_uIntPtr nDstNode1=pSrcNode1->GetOrdNum();
185 SdrObject* pDstNode1=GetObj(nDstNode1);
186 if (pDstNode1!=NULL) { // else we get an error!
187 pDstEdge->ConnectToNode(sal_True,pDstNode1);
188 } else {
189 OSL_FAIL("SdrObjList::operator=(): pDstNode1==NULL!");
192 if (pSrcNode2!=NULL) {
193 sal_uIntPtr nDstNode2=pSrcNode2->GetOrdNum();
194 SdrObject* pDstNode2=GetObj(nDstNode2);
195 if (pDstNode2!=NULL) { // else the node was probably not selected
196 pDstEdge->ConnectToNode(sal_False,pDstNode2);
197 } else {
198 OSL_FAIL("SdrObjList::operator=(): pDstNode2==NULL!");
201 } else {
202 OSL_FAIL("SdrObjList::operator=(): pDstEdge==NULL!");
207 } else {
208 #ifdef DBG_UTIL
209 rtl::OStringBuffer aStr(RTL_CONSTASCII_STRINGPARAM(
210 "SdrObjList::operator=(): Error when cloning "));
212 if(nCloneErrCnt == 1)
214 aStr.append(RTL_CONSTASCII_STRINGPARAM("a drawing object."));
216 else
218 aStr.append(static_cast<sal_Int32>(nCloneErrCnt));
219 aStr.append(RTL_CONSTASCII_STRINGPARAM(" drawing objects."));
222 aStr.append(RTL_CONSTASCII_STRINGPARAM(
223 " Not copying connectors."));
225 OSL_FAIL(aStr.getStr());
226 #endif
230 void SdrObjList::Clear()
232 sal_Bool bObjectsRemoved(sal_False);
234 while( ! maList.empty())
236 // remove last object from list
237 SdrObject* pObj = maList.back();
238 RemoveObjectFromContainer(maList.size()-1);
240 // flushViewObjectContacts() is done since SdrObject::Free is not guaranteed
241 // to delete the object and thus refresh visualisations
242 pObj->GetViewContact().flushViewObjectContacts(true);
244 bObjectsRemoved = sal_True;
246 // sent remove hint (after removal, see RemoveObject())
247 if(pModel)
249 SdrHint aHint(*pObj);
250 aHint.SetKind(HINT_OBJREMOVED);
251 aHint.SetPage(pPage);
252 pModel->Broadcast(aHint);
255 // delete the object itself
256 SdrObject::Free( pObj );
259 if(pModel && bObjectsRemoved)
261 pModel->SetChanged();
265 SdrPage* SdrObjList::GetPage() const
267 return pPage;
270 void SdrObjList::SetPage(SdrPage* pNewPage)
272 if (pPage!=pNewPage) {
273 pPage=pNewPage;
274 sal_uIntPtr nAnz=GetObjCount();
275 for (sal_uIntPtr no=0; no<nAnz; no++) {
276 SdrObject* pObj=GetObj(no);
277 pObj->SetPage(pPage);
282 SdrModel* SdrObjList::GetModel() const
284 return pModel;
287 void SdrObjList::SetModel(SdrModel* pNewModel)
289 if (pModel!=pNewModel) {
290 pModel=pNewModel;
291 sal_uIntPtr nAnz=GetObjCount();
292 for (sal_uIntPtr i=0; i<nAnz; i++) {
293 SdrObject* pObj=GetObj(i);
294 pObj->SetModel(pModel);
299 void SdrObjList::RecalcObjOrdNums()
301 sal_uIntPtr nAnz=GetObjCount();
302 for (sal_uIntPtr no=0; no<nAnz; no++) {
303 SdrObject* pObj=GetObj(no);
304 pObj->SetOrdNum(no);
306 bObjOrdNumsDirty=sal_False;
309 void SdrObjList::RecalcRects()
311 aOutRect=Rectangle();
312 aSnapRect=aOutRect;
313 sal_uIntPtr nAnz=GetObjCount();
314 sal_uIntPtr i;
315 for (i=0; i<nAnz; i++) {
316 SdrObject* pObj=GetObj(i);
317 if (i==0) {
318 aOutRect=pObj->GetCurrentBoundRect();
319 aSnapRect=pObj->GetSnapRect();
320 } else {
321 aOutRect.Union(pObj->GetCurrentBoundRect());
322 aSnapRect.Union(pObj->GetSnapRect());
327 void SdrObjList::SetRectsDirty()
329 bRectsDirty=sal_True;
330 if (pUpList!=NULL) pUpList->SetRectsDirty();
333 void SdrObjList::impChildInserted(SdrObject& rChild) const
335 sdr::contact::ViewContact* pParent = rChild.GetViewContact().GetParentContact();
337 if(pParent)
339 pParent->ActionChildInserted(rChild.GetViewContact());
343 void SdrObjList::NbcInsertObject(SdrObject* pObj, sal_uIntPtr nPos, const SdrInsertReason* /*pReason*/)
345 DBG_ASSERT(pObj!=NULL,"SdrObjList::NbcInsertObject(NULL)");
346 if (pObj!=NULL) {
347 DBG_ASSERT(!pObj->IsInserted(),"ZObjekt already has the status Inserted.");
348 sal_uIntPtr nAnz=GetObjCount();
349 if (nPos>nAnz) nPos=nAnz;
350 InsertObjectIntoContainer(*pObj,nPos);
352 if (nPos<nAnz) bObjOrdNumsDirty=sal_True;
353 pObj->SetOrdNum(nPos);
354 pObj->SetObjList(this);
355 pObj->SetPage(pPage);
357 // Inform the parent about change to allow invalidations at
358 // evtl. existing parent visualisations
359 impChildInserted(*pObj);
361 if (!bRectsDirty) {
362 aOutRect.Union(pObj->GetCurrentBoundRect());
363 aSnapRect.Union(pObj->GetSnapRect());
365 pObj->SetInserted(sal_True); // calls the UserCall (among others)
369 void SdrObjList::InsertObject(SdrObject* pObj, sal_uIntPtr nPos, const SdrInsertReason* pReason)
371 DBG_ASSERT(pObj!=NULL,"SdrObjList::InsertObject(NULL)");
373 if(pObj)
375 // if anchor is used, reset it before grouping
376 if(GetOwnerObj())
378 const Point& rAnchorPos = pObj->GetAnchorPos();
379 if(rAnchorPos.X() || rAnchorPos.Y())
380 pObj->NbcSetAnchorPos(Point());
383 // do insert to new group
384 NbcInsertObject(pObj, nPos, pReason);
386 // In case the object is inserted into a group and doesn't overlap with
387 // the group's other members, it needs an own repaint.
388 if(pOwnerObj)
390 // only repaint here
391 pOwnerObj->ActionChanged();
394 if(pModel)
396 // TODO: We need a different broadcast here!
397 // Repaint from object number ... (heads-up: GroupObj)
398 if(pObj->GetPage())
400 SdrHint aHint(*pObj);
402 aHint.SetKind(HINT_OBJINSERTED);
403 pModel->Broadcast(aHint);
406 pModel->SetChanged();
411 SdrObject* SdrObjList::NbcRemoveObject(sal_uIntPtr nObjNum)
413 if (nObjNum >= maList.size())
415 OSL_ASSERT(nObjNum<maList.size());
416 return NULL;
419 sal_uIntPtr nAnz=GetObjCount();
420 SdrObject* pObj=maList[nObjNum];
421 RemoveObjectFromContainer(nObjNum);
423 DBG_ASSERT(pObj!=NULL,"Could not find object to remove.");
424 if (pObj!=NULL) {
425 // flushViewObjectContacts() clears the VOC's and those invalidate
426 pObj->GetViewContact().flushViewObjectContacts(true);
428 DBG_ASSERT(pObj->IsInserted(),"ZObjekt does not have the status Inserted.");
429 pObj->SetInserted(sal_False); // Ruft u.a. den UserCall
430 pObj->SetObjList(NULL);
431 pObj->SetPage(NULL);
432 if (!bObjOrdNumsDirty) { // optimizing for the case that the last object has to be removed
433 if (nObjNum!=sal_uIntPtr(nAnz-1)) {
434 bObjOrdNumsDirty=sal_True;
437 SetRectsDirty();
439 return pObj;
442 SdrObject* SdrObjList::RemoveObject(sal_uIntPtr nObjNum)
444 if (nObjNum >= maList.size())
446 OSL_ASSERT(nObjNum<maList.size());
447 return NULL;
450 sal_uIntPtr nAnz=GetObjCount();
451 SdrObject* pObj=maList[nObjNum];
452 RemoveObjectFromContainer(nObjNum);
454 DBG_ASSERT(pObj!=NULL,"Object to remove not found.");
455 if(pObj)
457 // flushViewObjectContacts() clears the VOC's and those invalidate
458 pObj->GetViewContact().flushViewObjectContacts(true);
460 DBG_ASSERT(pObj->IsInserted(),"ZObjekt does not have the status Inserted.");
461 if (pModel!=NULL) {
462 // TODO: We need a different broadcast here.
463 if (pObj->GetPage()!=NULL) {
464 SdrHint aHint(*pObj);
465 aHint.SetKind(HINT_OBJREMOVED);
466 pModel->Broadcast(aHint);
468 pModel->SetChanged();
470 pObj->SetInserted(sal_False); // calls, among other things, the UserCall
471 pObj->SetObjList(NULL);
472 pObj->SetPage(NULL);
473 if (!bObjOrdNumsDirty) { // optimization for the case that the last object is removed
474 if (nObjNum!=sal_uIntPtr(nAnz-1)) {
475 bObjOrdNumsDirty=sal_True;
478 SetRectsDirty();
480 if(pOwnerObj && !GetObjCount())
482 // empty group created; it needs to be repainted since it's
483 // visualization changes
484 pOwnerObj->ActionChanged();
487 return pObj;
490 SdrObject* SdrObjList::NbcReplaceObject(SdrObject* pNewObj, sal_uIntPtr nObjNum)
492 if (nObjNum >= maList.size() || pNewObj == NULL)
494 OSL_ASSERT(nObjNum<maList.size());
495 OSL_ASSERT(pNewObj!=NULL);
496 return NULL;
499 SdrObject* pObj=maList[nObjNum];
500 DBG_ASSERT(pObj!=NULL,"SdrObjList::ReplaceObject: Could not find object to remove.");
501 if (pObj!=NULL) {
502 DBG_ASSERT(pObj->IsInserted(),"SdrObjList::ReplaceObject: ZObjekt does not have status Inserted.");
503 pObj->SetInserted(sal_False);
504 pObj->SetObjList(NULL);
505 pObj->SetPage(NULL);
506 ReplaceObjectInContainer(*pNewObj,nObjNum);
508 // flushViewObjectContacts() clears the VOC's and those invalidate
509 pObj->GetViewContact().flushViewObjectContacts(true);
511 pNewObj->SetOrdNum(nObjNum);
512 pNewObj->SetObjList(this);
513 pNewObj->SetPage(pPage);
515 // Inform the parent about change to allow invalidations at
516 // evtl. existing parent visualisations
517 impChildInserted(*pNewObj);
519 pNewObj->SetInserted(sal_True);
520 SetRectsDirty();
522 return pObj;
525 SdrObject* SdrObjList::ReplaceObject(SdrObject* pNewObj, sal_uIntPtr nObjNum)
527 if (nObjNum >= maList.size())
529 OSL_ASSERT(nObjNum<maList.size());
530 return NULL;
532 if (pNewObj == NULL)
534 OSL_ASSERT(pNewObj!=NULL);
535 return NULL;
538 SdrObject* pObj=maList[nObjNum];
539 DBG_ASSERT(pObj!=NULL,"SdrObjList::ReplaceObject: Could not find object to remove.");
540 if (pObj!=NULL) {
541 DBG_ASSERT(pObj->IsInserted(),"SdrObjList::ReplaceObject: ZObjekt does not have status Inserted.");
542 if (pModel!=NULL) {
543 // TODO: We need a different broadcast here.
544 if (pObj->GetPage()!=NULL) {
545 SdrHint aHint(*pObj);
546 aHint.SetKind(HINT_OBJREMOVED);
547 pModel->Broadcast(aHint);
550 pObj->SetInserted(sal_False);
551 pObj->SetObjList(NULL);
552 pObj->SetPage(NULL);
553 ReplaceObjectInContainer(*pNewObj,nObjNum);
555 // flushViewObjectContacts() clears the VOC's and those invalidate
556 pObj->GetViewContact().flushViewObjectContacts(true);
558 pNewObj->SetOrdNum(nObjNum);
559 pNewObj->SetObjList(this);
560 pNewObj->SetPage(pPage);
562 // Inform the parent about change to allow invalidations at
563 // evtl. existing parent visualisations
564 impChildInserted(*pNewObj);
566 pNewObj->SetInserted(sal_True);
567 if (pModel!=NULL) {
568 // TODO: We need a different broadcast here.
569 if (pNewObj->GetPage()!=NULL) {
570 SdrHint aHint(*pNewObj);
571 aHint.SetKind(HINT_OBJINSERTED);
572 pModel->Broadcast(aHint);
574 pModel->SetChanged();
576 SetRectsDirty();
578 return pObj;
581 SdrObject* SdrObjList::NbcSetObjectOrdNum(sal_uIntPtr nOldObjNum, sal_uIntPtr nNewObjNum)
583 if (nOldObjNum >= maList.size() || nNewObjNum >= maList.size())
585 OSL_ASSERT(nOldObjNum<maList.size());
586 OSL_ASSERT(nNewObjNum<maList.size());
587 return NULL;
590 SdrObject* pObj=maList[nOldObjNum];
591 if (nOldObjNum==nNewObjNum) return pObj;
592 DBG_ASSERT(pObj!=NULL,"SdrObjList::NbcSetObjectOrdNum: Object not found.");
593 if (pObj!=NULL) {
594 DBG_ASSERT(pObj->IsInserted(),"SdrObjList::NbcSetObjectOrdNum: ZObjekt does not have status Inserted.");
595 RemoveObjectFromContainer(nOldObjNum);
597 InsertObjectIntoContainer(*pObj,nNewObjNum);
599 // No need to delete visualisation data since same object
600 // gets inserted again. Also a single ActionChanged is enough
601 pObj->ActionChanged();
603 pObj->SetOrdNum(nNewObjNum);
604 bObjOrdNumsDirty=sal_True;
606 return pObj;
609 SdrObject* SdrObjList::SetObjectOrdNum(sal_uIntPtr nOldObjNum, sal_uIntPtr nNewObjNum)
611 if (nOldObjNum >= maList.size() || nNewObjNum >= maList.size())
613 OSL_ASSERT(nOldObjNum<maList.size());
614 OSL_ASSERT(nNewObjNum<maList.size());
615 return NULL;
618 SdrObject* pObj=maList[nOldObjNum];
619 if (nOldObjNum==nNewObjNum) return pObj;
620 DBG_ASSERT(pObj!=NULL,"SdrObjList::SetObjectOrdNum: Object not found.");
621 if (pObj!=NULL) {
622 DBG_ASSERT(pObj->IsInserted(),"SdrObjList::SetObjectOrdNum: ZObjekt does not have status Inserted.");
623 RemoveObjectFromContainer(nOldObjNum);
624 InsertObjectIntoContainer(*pObj,nNewObjNum);
626 // No need to delete visualisation data since same object
627 // gets inserted again. Also a single ActionChanged is enough
628 pObj->ActionChanged();
630 pObj->SetOrdNum(nNewObjNum);
631 bObjOrdNumsDirty=sal_True;
632 if (pModel!=NULL)
634 // TODO: We need a different broadcast here.
635 if (pObj->GetPage()!=NULL) pModel->Broadcast(SdrHint(*pObj));
636 pModel->SetChanged();
639 return pObj;
642 const Rectangle& SdrObjList::GetAllObjSnapRect() const
644 if (bRectsDirty) {
645 ((SdrObjList*)this)->RecalcRects();
646 ((SdrObjList*)this)->bRectsDirty=sal_False;
648 return aSnapRect;
651 const Rectangle& SdrObjList::GetAllObjBoundRect() const
653 // #i106183# for deep group hierarchies like in chart2, the invalidates
654 // through the hierarchy are not correct; use a 2nd hint for the needed
655 // recalculation. Future versions will have no bool flag at all, but
656 // just aOutRect in empty state to represent an invalid state, thus
657 // it's a step in the right direction.
658 if (bRectsDirty || aOutRect.IsEmpty())
660 ((SdrObjList*)this)->RecalcRects();
661 ((SdrObjList*)this)->bRectsDirty=sal_False;
663 return aOutRect;
666 void SdrObjList::NbcReformatAllTextObjects()
668 sal_uIntPtr nAnz=GetObjCount();
669 sal_uIntPtr nNum=0;
671 while (nNum<nAnz)
673 SdrObject* pObj = GetObj(nNum);
675 pObj->NbcReformatText();
676 nAnz=GetObjCount(); // ReformatText may delete an object
677 nNum++;
682 void SdrObjList::ReformatAllTextObjects()
684 NbcReformatAllTextObjects();
687 /** steps over all available objects and reformats all
688 edge objects that are connected to other objects so that
689 they may reposition themselves.
691 void SdrObjList::ReformatAllEdgeObjects()
693 const sal_uInt32 nCount=GetObjCount();
694 sal_uInt32 nObj;
696 for( nObj = 0; nObj < nCount; nObj++ )
698 SdrObject* pObj = GetObj(nObj);
699 if( pObj->ISA(SdrEdgeObj) )
700 static_cast<SdrEdgeObj*>(pObj)->Reformat();
704 void SdrObjList::BurnInStyleSheetAttributes()
706 for(sal_uInt32 a(0L); a < GetObjCount(); a++)
708 GetObj(a)->BurnInStyleSheetAttributes();
712 sal_uIntPtr SdrObjList::GetObjCount() const
714 return maList.size();
720 SdrObject* SdrObjList::GetObj(sal_uIntPtr nNum) const
722 if (nNum >= maList.size())
724 OSL_ASSERT(nNum<maList.size());
725 return NULL;
727 else
728 return maList[nNum];
734 bool SdrObjList::IsReadOnly() const
736 bool bRet = false;
737 if (pPage!=NULL && pPage!=this) bRet=pPage->IsReadOnly();
738 return bRet;
741 sal_uIntPtr SdrObjList::CountAllObjects() const
743 sal_uIntPtr nCnt=GetObjCount();
744 sal_uIntPtr nAnz=nCnt;
745 for (sal_uInt16 nNum=0; nNum<nAnz; nNum++) {
746 SdrObjList* pSubOL=GetObj(nNum)->GetSubList();
747 if (pSubOL!=NULL) {
748 nCnt+=pSubOL->CountAllObjects();
751 return nCnt;
754 void SdrObjList::ForceSwapInObjects() const
756 sal_uIntPtr nObjAnz=GetObjCount();
757 for (sal_uIntPtr nObjNum=nObjAnz; nObjNum>0;) {
758 SdrObject* pObj=GetObj(--nObjNum);
759 SdrGrafObj* pGrafObj=PTR_CAST(SdrGrafObj,pObj);
760 if (pGrafObj!=NULL) {
761 pGrafObj->ForceSwapIn();
763 SdrObjList* pOL=pObj->GetSubList();
764 if (pOL!=NULL) {
765 pOL->ForceSwapInObjects();
770 void SdrObjList::ForceSwapOutObjects() const
772 sal_uIntPtr nObjAnz=GetObjCount();
773 for (sal_uIntPtr nObjNum=nObjAnz; nObjNum>0;) {
774 SdrObject* pObj=GetObj(--nObjNum);
775 SdrGrafObj* pGrafObj=PTR_CAST(SdrGrafObj,pObj);
776 if (pGrafObj!=NULL) {
777 pGrafObj->ForceSwapOut();
779 SdrObjList* pOL=pObj->GetSubList();
780 if (pOL!=NULL) {
781 pOL->ForceSwapOutObjects();
786 void SdrObjList::FlattenGroups()
788 sal_Int32 nObj = GetObjCount();
789 sal_Int32 i;
790 for( i=nObj-1; i>=0; --i)
791 UnGroupObj(i);
794 void SdrObjList::UnGroupObj( sal_uIntPtr nObjNum )
796 // if the given object is no group, this method is a noop
797 SdrObject* pUngroupObj = GetObj( nObjNum );
798 if( pUngroupObj )
800 SdrObjList* pSrcLst = pUngroupObj->GetSubList();
801 if( pUngroupObj->ISA( SdrObjGroup ) && pSrcLst )
803 SdrObjGroup* pUngroupGroup = static_cast< SdrObjGroup* > (pUngroupObj);
805 // ungroup recursively (has to be head recursion,
806 // otherwise our indices will get trashed when doing it in
807 // the loop)
808 pSrcLst->FlattenGroups();
810 // the position at which we insert the members of rUngroupGroup
811 sal_Int32 nInsertPos( pUngroupGroup->GetOrdNum() );
813 SdrObject* pObj;
814 sal_Int32 i, nAnz = pSrcLst->GetObjCount();
815 for( i=0; i<nAnz; ++i )
817 pObj = pSrcLst->RemoveObject(0);
818 SdrInsertReason aReason(SDRREASON_VIEWCALL, pUngroupGroup);
819 InsertObject(pObj, nInsertPos, &aReason);
820 ++nInsertPos;
823 RemoveObject(nInsertPos);
826 #ifdef DBG_UTIL
827 else
828 OSL_FAIL("SdrObjList::UnGroupObj: object index invalid");
829 #endif
835 bool SdrObjList::HasObjectNavigationOrder (void) const
837 return mpNavigationOrder.get() != NULL;
843 void SdrObjList::SetObjectNavigationPosition (
844 SdrObject& rObject,
845 const sal_uInt32 nNewPosition)
847 // When the navigation order container has not yet been created then
848 // create one now. It is initialized with the z-order taken from
849 // maList.
850 if (mpNavigationOrder.get() == NULL)
852 mpNavigationOrder.reset(new WeakSdrObjectContainerType(maList.size()));
853 ::std::copy(
854 maList.begin(),
855 maList.end(),
856 mpNavigationOrder->begin());
858 OSL_ASSERT(mpNavigationOrder.get()!=NULL);
859 OSL_ASSERT( mpNavigationOrder->size() == maList.size());
861 SdrObjectWeakRef aReference (&rObject);
863 // Look up the object whose navigation position is to be changed.
864 WeakSdrObjectContainerType::iterator iObject (::std::find(
865 mpNavigationOrder->begin(),
866 mpNavigationOrder->end(),
867 aReference));
868 if (iObject == mpNavigationOrder->end())
870 // The given object is not a member of the navigation order.
871 return;
874 // Move the object to its new position.
875 const sal_uInt32 nOldPosition = ::std::distance(mpNavigationOrder->begin(), iObject);
876 if (nOldPosition != nNewPosition)
878 mpNavigationOrder->erase(iObject);
879 sal_uInt32 nInsertPosition (nNewPosition);
880 // Adapt insertion position for the just erased object.
881 if (nNewPosition >= nOldPosition)
882 nInsertPosition -= 1;
883 if (nInsertPosition >= mpNavigationOrder->size())
884 mpNavigationOrder->push_back(aReference);
885 else
886 mpNavigationOrder->insert(mpNavigationOrder->begin()+nInsertPosition, aReference);
888 mbIsNavigationOrderDirty = true;
890 // The navigation order is written out to file so mark the model as modified.
891 if (pModel != NULL)
892 pModel->SetChanged();
899 SdrObject* SdrObjList::GetObjectForNavigationPosition (const sal_uInt32 nNavigationPosition) const
901 if (HasObjectNavigationOrder())
903 // There is a user defined navigation order. Make sure the object
904 // index is correct and look up the object in mpNavigationOrder.
905 if (nNavigationPosition >= mpNavigationOrder->size())
907 OSL_ASSERT(nNavigationPosition < mpNavigationOrder->size());
909 else
910 return (*mpNavigationOrder)[nNavigationPosition].get();
912 else
914 // There is no user defined navigation order. Use the z-order
915 // instead.
916 if (nNavigationPosition >= maList.size())
918 OSL_ASSERT(nNavigationPosition < maList.size());
920 else
921 return maList[nNavigationPosition];
923 return NULL;
929 void SdrObjList::ClearObjectNavigationOrder (void)
931 mpNavigationOrder.reset();
932 mbIsNavigationOrderDirty = true;
938 bool SdrObjList::RecalcNavigationPositions (void)
940 if (mbIsNavigationOrderDirty)
942 if (mpNavigationOrder.get() != NULL)
944 mbIsNavigationOrderDirty = false;
946 WeakSdrObjectContainerType::iterator iObject;
947 WeakSdrObjectContainerType::const_iterator iEnd (mpNavigationOrder->end());
948 sal_uInt32 nIndex (0);
949 for (iObject=mpNavigationOrder->begin(); iObject!=iEnd; ++iObject,++nIndex)
950 (*iObject)->SetNavigationPosition(nIndex);
954 return mpNavigationOrder.get() != NULL;
960 void SdrObjList::SetNavigationOrder (const uno::Reference<container::XIndexAccess>& rxOrder)
962 if (rxOrder.is())
964 const sal_Int32 nCount = rxOrder->getCount();
965 if ((sal_uInt32)nCount != maList.size())
966 return;
968 if (mpNavigationOrder.get() == NULL)
969 mpNavigationOrder.reset(new WeakSdrObjectContainerType(nCount));
971 for (sal_Int32 nIndex=0; nIndex<nCount; ++nIndex)
973 uno::Reference<uno::XInterface> xShape (rxOrder->getByIndex(nIndex), uno::UNO_QUERY);
974 SdrObject* pObject = SdrObject::getSdrObjectFromXShape(xShape);
975 if (pObject == NULL)
976 break;
977 (*mpNavigationOrder)[nIndex] = pObject;
980 mbIsNavigationOrderDirty = true;
982 else
983 ClearObjectNavigationOrder();
989 void SdrObjList::InsertObjectIntoContainer (
990 SdrObject& rObject,
991 const sal_uInt32 nInsertPosition)
993 OSL_ASSERT(nInsertPosition<=maList.size());
995 // Update the navigation positions.
996 if (HasObjectNavigationOrder())
998 // The new object does not have a user defined position so append it
999 // to the list.
1000 rObject.SetNavigationPosition(mpNavigationOrder->size());
1001 mpNavigationOrder->push_back(&rObject);
1004 // Insert object into object list. Because the insert() method requires
1005 // a valid iterator as insertion position, we have to use push_back() to
1006 // insert at the end of the list.
1007 if (nInsertPosition >= maList.size())
1008 maList.push_back(&rObject);
1009 else
1010 maList.insert(maList.begin()+nInsertPosition, &rObject);
1011 bObjOrdNumsDirty=sal_True;
1017 void SdrObjList::ReplaceObjectInContainer (
1018 SdrObject& rNewObject,
1019 const sal_uInt32 nObjectPosition)
1021 if (nObjectPosition >= maList.size())
1023 OSL_ASSERT(nObjectPosition<maList.size());
1024 return;
1027 // Update the navigation positions.
1028 if (HasObjectNavigationOrder())
1030 // A user defined position of the object that is to be replaced is
1031 // not transferred to the new object so erase the former and append
1032 // the later object from/to the navigation order.
1033 OSL_ASSERT(nObjectPosition < maList.size());
1034 SdrObjectWeakRef aReference (maList[nObjectPosition]);
1035 WeakSdrObjectContainerType::iterator iObject (::std::find(
1036 mpNavigationOrder->begin(),
1037 mpNavigationOrder->end(),
1038 aReference));
1039 if (iObject != mpNavigationOrder->end())
1040 mpNavigationOrder->erase(iObject);
1042 mpNavigationOrder->push_back(&rNewObject);
1044 mbIsNavigationOrderDirty = true;
1047 maList[nObjectPosition] = &rNewObject;
1048 bObjOrdNumsDirty=sal_True;
1054 void SdrObjList::RemoveObjectFromContainer (
1055 const sal_uInt32 nObjectPosition)
1057 if (nObjectPosition >= maList.size())
1059 OSL_ASSERT(nObjectPosition<maList.size());
1060 return;
1063 // Update the navigation positions.
1064 if (HasObjectNavigationOrder())
1066 SdrObjectWeakRef aReference (maList[nObjectPosition]);
1067 WeakSdrObjectContainerType::iterator iObject (::std::find(
1068 mpNavigationOrder->begin(),
1069 mpNavigationOrder->end(),
1070 aReference));
1071 if (iObject != mpNavigationOrder->end())
1072 mpNavigationOrder->erase(iObject);
1073 mbIsNavigationOrderDirty = true;
1076 maList.erase(maList.begin()+nObjectPosition);
1077 bObjOrdNumsDirty=sal_True;
1083 ////////////////////////////////////////////////////////////////////////////////////////////////////
1085 void SdrPageGridFrameList::Clear()
1087 sal_uInt16 nAnz=GetCount();
1088 for (sal_uInt16 i=0; i<nAnz; i++) {
1089 delete GetObject(i);
1091 aList.Clear();
1094 //////////////////////////////////////////////////////////////////////////////
1095 // PageUser section
1097 void SdrPage::AddPageUser(sdr::PageUser& rNewUser)
1099 maPageUsers.push_back(&rNewUser);
1102 void SdrPage::RemovePageUser(sdr::PageUser& rOldUser)
1104 const ::sdr::PageUserVector::iterator aFindResult = ::std::find(maPageUsers.begin(), maPageUsers.end(), &rOldUser);
1105 if(aFindResult != maPageUsers.end())
1107 maPageUsers.erase(aFindResult);
1111 //////////////////////////////////////////////////////////////////////////////
1112 // DrawContact section
1114 sdr::contact::ViewContact* SdrPage::CreateObjectSpecificViewContact()
1116 return new sdr::contact::ViewContactOfSdrPage(*this);
1119 sdr::contact::ViewContact& SdrPage::GetViewContact() const
1121 if(!mpViewContact)
1123 const_cast< SdrPage* >(this)->mpViewContact =
1124 const_cast< SdrPage* >(this)->CreateObjectSpecificViewContact();
1127 return *mpViewContact;
1130 ////////////////////////////////////////////////////////////////////////////////////////////////////
1132 void SdrPageProperties::ImpRemoveStyleSheet()
1134 if(mpStyleSheet)
1136 EndListening(*mpStyleSheet);
1137 mpProperties->SetParent(0);
1138 mpStyleSheet = 0;
1142 void SdrPageProperties::ImpAddStyleSheet(SfxStyleSheet& rNewStyleSheet)
1144 if(mpStyleSheet != &rNewStyleSheet)
1146 ImpRemoveStyleSheet();
1147 mpStyleSheet = &rNewStyleSheet;
1148 StartListening(rNewStyleSheet);
1149 mpProperties->SetParent(&rNewStyleSheet.GetItemSet());
1153 void ImpPageChange(SdrPage& rSdrPage)
1155 rSdrPage.ActionChanged();
1157 if(rSdrPage.GetModel())
1159 rSdrPage.GetModel()->SetChanged(true);
1160 SdrHint aHint(HINT_PAGEORDERCHG);
1161 aHint.SetPage(&rSdrPage);
1162 rSdrPage.GetModel()->Broadcast(aHint);
1166 SdrPageProperties::SdrPageProperties(SdrPage& rSdrPage)
1167 : SfxListener(),
1168 mpSdrPage(&rSdrPage),
1169 mpStyleSheet(0),
1170 mpProperties(new SfxItemSet(mpSdrPage->GetModel()->GetItemPool(), XATTR_FILL_FIRST, XATTR_FILL_LAST))
1172 if(!rSdrPage.IsMasterPage())
1174 mpProperties->Put(XFillStyleItem(XFILL_NONE));
1178 SdrPageProperties::~SdrPageProperties()
1180 ImpRemoveStyleSheet();
1181 delete mpProperties;
1184 void SdrPageProperties::Notify(SfxBroadcaster& /*rBC*/, const SfxHint& rHint)
1186 const SfxSimpleHint* pSimpleHint = dynamic_cast< const SfxSimpleHint* >(&rHint);
1188 if(pSimpleHint)
1190 switch(pSimpleHint->GetId())
1192 case SFX_HINT_DATACHANGED :
1194 // notify change, broadcast
1195 ImpPageChange(*mpSdrPage);
1196 break;
1198 case SFX_HINT_DYING :
1200 // Style needs to be forgotten
1201 ImpRemoveStyleSheet();
1202 break;
1208 const SfxItemSet& SdrPageProperties::GetItemSet() const
1210 return *mpProperties;
1213 void SdrPageProperties::PutItemSet(const SfxItemSet& rSet)
1215 OSL_ENSURE(!mpSdrPage->IsMasterPage(), "Item set at MasterPage Attributes (!)");
1216 mpProperties->Put(rSet);
1217 ImpPageChange(*mpSdrPage);
1220 void SdrPageProperties::PutItem(const SfxPoolItem& rItem)
1222 OSL_ENSURE(!mpSdrPage->IsMasterPage(), "Item set at MasterPage Attributes (!)");
1223 mpProperties->Put(rItem);
1224 ImpPageChange(*mpSdrPage);
1227 void SdrPageProperties::ClearItem(const sal_uInt16 nWhich)
1229 mpProperties->ClearItem(nWhich);
1230 ImpPageChange(*mpSdrPage);
1233 void SdrPageProperties::SetStyleSheet(SfxStyleSheet* pStyleSheet)
1235 if(pStyleSheet)
1237 ImpAddStyleSheet(*pStyleSheet);
1239 else
1241 ImpRemoveStyleSheet();
1244 ImpPageChange(*mpSdrPage);
1247 SfxStyleSheet* SdrPageProperties::GetStyleSheet() const
1249 return mpStyleSheet;
1252 ////////////////////////////////////////////////////////////////////////////////////////////////////
1254 TYPEINIT1(SdrPage,SdrObjList);
1255 DBG_NAME(SdrPage)
1256 SdrPage::SdrPage(SdrModel& rNewModel, bool bMasterPage)
1257 : SdrObjList(&rNewModel, this),
1258 mpViewContact(0L),
1259 nWdt(10L),
1260 nHgt(10L),
1261 nBordLft(0L),
1262 nBordUpp(0L),
1263 nBordRgt(0L),
1264 nBordLwr(0L),
1265 pLayerAdmin(new SdrLayerAdmin(&rNewModel.GetLayerAdmin())),
1266 mpSdrPageProperties(0),
1267 mpMasterPageDescriptor(0L),
1268 nPageNum(0L),
1269 mbMaster(bMasterPage),
1270 mbInserted(false),
1271 mbObjectsNotPersistent(false),
1272 mbSwappingLocked(false),
1273 mbPageBorderOnlyLeftRight(false)
1275 DBG_CTOR(SdrPage,NULL);
1276 aPrefVisiLayers.SetAll();
1277 eListKind = (bMasterPage) ? SDROBJLIST_MASTERPAGE : SDROBJLIST_DRAWPAGE;
1279 mpSdrPageProperties = new SdrPageProperties(*this);
1282 SdrPage::SdrPage(const SdrPage& rSrcPage)
1283 : SdrObjList(rSrcPage.pModel, this),
1284 tools::WeakBase< SdrPage >(),
1285 mpViewContact(0L),
1286 nWdt(rSrcPage.nWdt),
1287 nHgt(rSrcPage.nHgt),
1288 nBordLft(rSrcPage.nBordLft),
1289 nBordUpp(rSrcPage.nBordUpp),
1290 nBordRgt(rSrcPage.nBordRgt),
1291 nBordLwr(rSrcPage.nBordLwr),
1292 pLayerAdmin(new SdrLayerAdmin(rSrcPage.pModel->GetLayerAdmin())),
1293 mpSdrPageProperties(0),
1294 mpMasterPageDescriptor(0L),
1295 nPageNum(rSrcPage.nPageNum),
1296 mbMaster(rSrcPage.mbMaster),
1297 mbInserted(false),
1298 mbObjectsNotPersistent(rSrcPage.mbObjectsNotPersistent),
1299 mbSwappingLocked(rSrcPage.mbSwappingLocked),
1300 mbPageBorderOnlyLeftRight(rSrcPage.mbPageBorderOnlyLeftRight)
1302 DBG_CTOR(SdrPage,NULL);
1303 aPrefVisiLayers.SetAll();
1304 eListKind = (mbMaster) ? SDROBJLIST_MASTERPAGE : SDROBJLIST_DRAWPAGE;
1306 // copy things from source
1307 // Warning: this leads to slicing (see issue 93186) and has to be
1308 // removed as soon as possible.
1309 *this = rSrcPage;
1310 OSL_ENSURE(mpSdrPageProperties,
1311 "SdrPage::SdrPage: operator= did not create needed SdrPageProperties (!)");
1313 // be careful and correct eListKind, a member of SdrObjList which
1314 // will be changed by the SdrOIbjList::operator= before...
1315 eListKind = (mbMaster) ? SDROBJLIST_MASTERPAGE : SDROBJLIST_DRAWPAGE;
1317 // The previous assignment to *this may have resulted in a call to
1318 // createUnoPage at a partially initialized (sliced) SdrPage object.
1319 // Due to the vtable being not yet fully set-up at this stage,
1320 // createUnoPage() may have been called at the wrong class.
1321 // To force a call to the right createUnoPage() at a later time when the
1322 // new object is full constructed mxUnoPage is disposed now.
1323 uno::Reference<lang::XComponent> xComponent (mxUnoPage, uno::UNO_QUERY);
1324 if (xComponent.is())
1326 mxUnoPage = NULL;
1327 xComponent->dispose();
1331 SdrPage::~SdrPage()
1333 if( mxUnoPage.is() ) try
1335 uno::Reference< lang::XComponent > xPageComponent( mxUnoPage, uno::UNO_QUERY_THROW );
1336 mxUnoPage.clear();
1337 xPageComponent->dispose();
1339 catch( const uno::Exception& )
1341 DBG_UNHANDLED_EXCEPTION();
1344 // tell all the registered PageUsers that the page is in destruction
1345 // This causes some (all?) PageUsers to remove themselves from the list
1346 // of page users. Therefore we have to use a copy of the list for the
1347 // iteration.
1348 ::sdr::PageUserVector aListCopy (maPageUsers.begin(), maPageUsers.end());
1349 for(::sdr::PageUserVector::iterator aIterator = aListCopy.begin(); aIterator != aListCopy.end(); ++aIterator)
1351 sdr::PageUser* pPageUser = *aIterator;
1352 DBG_ASSERT(pPageUser, "SdrPage::~SdrPage: corrupt PageUser list (!)");
1353 pPageUser->PageInDestruction(*this);
1356 // Clear the vector. This means that user do not need to call RemovePageUser()
1357 // when they get called from PageInDestruction().
1358 maPageUsers.clear();
1360 delete pLayerAdmin;
1362 TRG_ClearMasterPage();
1364 if(mpViewContact)
1366 delete mpViewContact;
1367 mpViewContact = 0L;
1371 delete mpSdrPageProperties;
1372 mpSdrPageProperties = 0;
1375 DBG_DTOR(SdrPage,NULL);
1378 SdrPage& SdrPage::operator=(const SdrPage& rSrcPage)
1380 if( this == &rSrcPage )
1381 return *this;
1382 if(mpViewContact)
1384 delete mpViewContact;
1385 mpViewContact = 0L;
1388 // Joe also sets some parameters for the class this one
1389 // is derived from. SdrObjList does the same bad handling of
1390 // copy constructor and operator=, so i better let it stand here.
1391 pPage = this;
1393 // copy all the local parameters to make this instance
1394 // a valid copy of source page before copying and inserting
1395 // the contained objects
1396 mbMaster = rSrcPage.mbMaster;
1397 mbSwappingLocked = rSrcPage.mbSwappingLocked;
1398 mbPageBorderOnlyLeftRight = rSrcPage.mbPageBorderOnlyLeftRight;
1399 aPrefVisiLayers = rSrcPage.aPrefVisiLayers;
1400 nWdt = rSrcPage.nWdt;
1401 nHgt = rSrcPage.nHgt;
1402 nBordLft = rSrcPage.nBordLft;
1403 nBordUpp = rSrcPage.nBordUpp;
1404 nBordRgt = rSrcPage.nBordRgt;
1405 nBordLwr = rSrcPage.nBordLwr;
1406 nPageNum = rSrcPage.nPageNum;
1408 if(rSrcPage.TRG_HasMasterPage())
1410 TRG_SetMasterPage(rSrcPage.TRG_GetMasterPage());
1411 TRG_SetMasterPageVisibleLayers(rSrcPage.TRG_GetMasterPageVisibleLayers());
1413 else
1415 TRG_ClearMasterPage();
1418 mbObjectsNotPersistent = rSrcPage.mbObjectsNotPersistent;
1421 // #i111122# delete SdrPageProperties when model is different
1422 if(mpSdrPageProperties && GetModel() != rSrcPage.GetModel())
1424 delete mpSdrPageProperties;
1425 mpSdrPageProperties = 0;
1428 if(!mpSdrPageProperties)
1430 mpSdrPageProperties = new SdrPageProperties(*this);
1432 else
1434 mpSdrPageProperties->ClearItem(0);
1437 if(!IsMasterPage())
1439 mpSdrPageProperties->PutItemSet(rSrcPage.getSdrPageProperties().GetItemSet());
1442 mpSdrPageProperties->SetStyleSheet(rSrcPage.getSdrPageProperties().GetStyleSheet());
1445 // Now copy the contained objects (by cloning them)
1446 SdrObjList::operator=(rSrcPage);
1447 return *this;
1450 SdrPage* SdrPage::Clone() const
1452 return Clone(NULL);
1455 SdrPage* SdrPage::Clone(SdrModel* pNewModel) const
1457 if (pNewModel==NULL) pNewModel=pModel;
1458 SdrPage* pPage2=new SdrPage(*pNewModel);
1459 *pPage2=*this;
1460 return pPage2;
1463 void SdrPage::SetSize(const Size& aSiz)
1465 bool bChanged(false);
1467 if(aSiz.Width() != nWdt)
1469 nWdt = aSiz.Width();
1470 bChanged = true;
1473 if(aSiz.Height() != nHgt)
1475 nHgt = aSiz.Height();
1476 bChanged = true;
1479 if(bChanged)
1481 SetChanged();
1485 Size SdrPage::GetSize() const
1487 return Size(nWdt,nHgt);
1490 sal_Int32 SdrPage::GetWdt() const
1492 return nWdt;
1495 void SdrPage::SetOrientation(Orientation eOri)
1497 // square: handle like portrait format
1498 Size aSiz(GetSize());
1499 if (aSiz.Width()!=aSiz.Height()) {
1500 if ((eOri==ORIENTATION_PORTRAIT) == (aSiz.Width()>aSiz.Height())) {
1501 SetSize(Size(aSiz.Height(),aSiz.Width()));
1506 Orientation SdrPage::GetOrientation() const
1508 // square: handle like portrait format
1509 Orientation eRet=ORIENTATION_PORTRAIT;
1510 Size aSiz(GetSize());
1511 if (aSiz.Width()>aSiz.Height()) eRet=ORIENTATION_LANDSCAPE;
1512 return eRet;
1515 sal_Int32 SdrPage::GetHgt() const
1517 return nHgt;
1520 void SdrPage::SetBorder(sal_Int32 nLft, sal_Int32 nUpp, sal_Int32 nRgt, sal_Int32 nLwr)
1522 bool bChanged(false);
1524 if(nBordLft != nLft)
1526 nBordLft = nLft;
1527 bChanged = true;
1530 if(nBordUpp != nUpp)
1532 nBordUpp = nUpp;
1533 bChanged = true;
1536 if(nBordRgt != nRgt)
1538 nBordRgt = nRgt;
1539 bChanged = true;
1542 if(nBordLwr != nLwr)
1544 nBordLwr = nLwr;
1545 bChanged = true;
1548 if(bChanged)
1550 SetChanged();
1554 void SdrPage::SetLftBorder(sal_Int32 nBorder)
1556 if(nBordLft != nBorder)
1558 nBordLft = nBorder;
1559 SetChanged();
1563 void SdrPage::SetUppBorder(sal_Int32 nBorder)
1565 if(nBordUpp != nBorder)
1567 nBordUpp = nBorder;
1568 SetChanged();
1572 void SdrPage::SetRgtBorder(sal_Int32 nBorder)
1574 if(nBordRgt != nBorder)
1576 nBordRgt=nBorder;
1577 SetChanged();
1581 void SdrPage::SetLwrBorder(sal_Int32 nBorder)
1583 if(nBordLwr != nBorder)
1585 nBordLwr=nBorder;
1586 SetChanged();
1590 sal_Int32 SdrPage::GetLftBorder() const
1592 return nBordLft;
1595 sal_Int32 SdrPage::GetUppBorder() const
1597 return nBordUpp;
1600 sal_Int32 SdrPage::GetRgtBorder() const
1602 return nBordRgt;
1605 sal_Int32 SdrPage::GetLwrBorder() const
1607 return nBordLwr;
1610 void SdrPage::SetModel(SdrModel* pNewModel)
1612 SdrModel* pOldModel=pModel;
1613 SdrObjList::SetModel(pNewModel);
1614 if (pNewModel!=pOldModel)
1616 if (pNewModel!=NULL) {
1617 pLayerAdmin->SetParent(&pNewModel->GetLayerAdmin());
1618 } else {
1619 pLayerAdmin->SetParent(NULL);
1621 pLayerAdmin->SetModel(pNewModel);
1623 // create new SdrPageProperties with new model (due to SfxItemSet there)
1624 // and copy ItemSet and StyleSheet
1625 SdrPageProperties *pNew = new SdrPageProperties(*this);
1627 if(!IsMasterPage())
1629 pNew->PutItemSet(getSdrPageProperties().GetItemSet());
1632 pNew->SetStyleSheet(getSdrPageProperties().GetStyleSheet());
1634 delete mpSdrPageProperties;
1635 mpSdrPageProperties = pNew;
1638 // update listeners at possible API wrapper object
1639 if( pOldModel != pNewModel )
1641 if( mxUnoPage.is() )
1643 SvxDrawPage* pPage2 = SvxDrawPage::getImplementation( mxUnoPage );
1644 if( pPage2 )
1645 pPage2->ChangeModel( pNewModel );
1650 ////////////////////////////////////////////////////////////////////////////////////////////////////
1652 // #i68775# React on PageNum changes (from Model in most cases)
1653 void SdrPage::SetPageNum(sal_uInt16 nNew)
1655 if(nNew != nPageNum)
1657 // change
1658 nPageNum = nNew;
1660 // notify visualisations, also notifies e.g. buffered MasterPages
1661 ActionChanged();
1665 sal_uInt16 SdrPage::GetPageNum() const
1667 if (!mbInserted)
1668 return 0;
1670 if (mbMaster) {
1671 if (pModel && pModel->IsMPgNumsDirty())
1672 ((SdrModel*)pModel)->RecalcPageNums(sal_True);
1673 } else {
1674 if (pModel && pModel->IsPagNumsDirty())
1675 ((SdrModel*)pModel)->RecalcPageNums(sal_False);
1677 return nPageNum;
1680 void SdrPage::SetChanged()
1682 // For test purposes, use the new ViewContact for change
1683 // notification now.
1684 ActionChanged();
1686 if( pModel )
1688 pModel->SetChanged();
1692 ////////////////////////////////////////////////////////////////////////////////////////////////////
1693 // MasterPage interface
1695 void SdrPage::TRG_SetMasterPage(SdrPage& rNew)
1697 if(mpMasterPageDescriptor && &(mpMasterPageDescriptor->GetUsedPage()) == &rNew)
1698 return;
1700 if(mpMasterPageDescriptor)
1701 TRG_ClearMasterPage();
1703 mpMasterPageDescriptor = new ::sdr::MasterPageDescriptor(*this, rNew);
1704 GetViewContact().ActionChanged();
1707 void SdrPage::TRG_ClearMasterPage()
1709 if(mpMasterPageDescriptor)
1711 SetChanged();
1713 // the flushViewObjectContacts() will do needed invalidates by deleting the involved VOCs
1714 mpMasterPageDescriptor->GetUsedPage().GetViewContact().flushViewObjectContacts(true);
1716 delete mpMasterPageDescriptor;
1717 mpMasterPageDescriptor = 0L;
1721 SdrPage& SdrPage::TRG_GetMasterPage() const
1723 DBG_ASSERT(mpMasterPageDescriptor != 0L, "TRG_GetMasterPage(): No MasterPage available. Use TRG_HasMasterPage() before access (!)");
1724 return mpMasterPageDescriptor->GetUsedPage();
1727 const SetOfByte& SdrPage::TRG_GetMasterPageVisibleLayers() const
1729 DBG_ASSERT(mpMasterPageDescriptor != 0L, "TRG_GetMasterPageVisibleLayers(): No MasterPage available. Use TRG_HasMasterPage() before access (!)");
1730 return mpMasterPageDescriptor->GetVisibleLayers();
1733 void SdrPage::TRG_SetMasterPageVisibleLayers(const SetOfByte& rNew)
1735 DBG_ASSERT(mpMasterPageDescriptor != 0L, "TRG_SetMasterPageVisibleLayers(): No MasterPage available. Use TRG_HasMasterPage() before access (!)");
1736 mpMasterPageDescriptor->SetVisibleLayers(rNew);
1739 sdr::contact::ViewContact& SdrPage::TRG_GetMasterPageDescriptorViewContact() const
1741 DBG_ASSERT(mpMasterPageDescriptor != 0L, "TRG_GetMasterPageDescriptorViewContact(): No MasterPage available. Use TRG_HasMasterPage() before access (!)");
1742 return mpMasterPageDescriptor->GetViewContact();
1745 // used from SdrModel::RemoveMasterPage
1746 void SdrPage::TRG_ImpMasterPageRemoved(const SdrPage& rRemovedPage)
1748 if(TRG_HasMasterPage())
1750 if(&TRG_GetMasterPage() == &rRemovedPage)
1752 TRG_ClearMasterPage();
1757 const SdrPageGridFrameList* SdrPage::GetGridFrameList(const SdrPageView* /*pPV*/, const Rectangle* /*pRect*/) const
1759 return NULL;
1762 XubString SdrPage::GetLayoutName() const
1764 return String();
1767 void SdrPage::SetInserted( bool bIns )
1769 if( (bool) mbInserted != bIns )
1771 mbInserted = bIns;
1773 SdrObjListIter aIter( *this, IM_FLAT );
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();
1789 uno::Reference< uno::XInterface > SdrPage::getUnoPage()
1791 // try weak reference first
1792 if( !mxUnoPage.is() )
1794 // create one
1795 mxUnoPage = createUnoPage();
1798 return mxUnoPage;
1801 uno::Reference< uno::XInterface > SdrPage::createUnoPage()
1803 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xInt =
1804 static_cast<cppu::OWeakObject*>( new SvxFmDrawPage( this ) );
1805 return xInt;
1808 SfxStyleSheet* SdrPage::GetTextStyleSheetForObject( SdrObject* pObj ) const
1810 return pObj->GetStyleSheet();
1813 /** returns an averaged background color of this page */
1814 // #i75566# GetBackgroundColor -> GetPageBackgroundColor and bScreenDisplay hint value
1815 Color SdrPage::GetPageBackgroundColor( SdrPageView* pView, bool bScreenDisplay ) const
1817 Color aColor;
1819 if(bScreenDisplay && (!pView || pView->GetApplicationDocumentColor() == COL_AUTO))
1821 svtools::ColorConfig aColorConfig;
1822 aColor = aColorConfig.GetColorValue( svtools::DOCCOLOR ).nColor;
1824 else
1826 aColor = pView->GetApplicationDocumentColor();
1829 const SfxItemSet* pBackgroundFill = &getSdrPageProperties().GetItemSet();
1831 if(!IsMasterPage() && TRG_HasMasterPage())
1833 if(XFILL_NONE == ((const XFillStyleItem&)pBackgroundFill->Get(XATTR_FILLSTYLE)).GetValue())
1835 pBackgroundFill = &TRG_GetMasterPage().getSdrPageProperties().GetItemSet();
1839 GetDraftFillColor(*pBackgroundFill, aColor);
1841 return aColor;
1844 /** *deprecated, use GetBackgroundColor with SdrPageView */
1845 Color SdrPage::GetPageBackgroundColor() const
1846 // #i75566# GetBackgroundColor -> GetPageBackgroundColor
1848 return GetPageBackgroundColor( NULL, true );
1851 /** this method returns true if the object from the ViewObjectContact should
1852 be visible on this page while rendering.
1853 bEdit selects if visibility test is for an editing view or a final render,
1854 like printing.
1856 bool SdrPage::checkVisibility(
1857 const sdr::contact::ViewObjectContact& /*rOriginal*/,
1858 const sdr::contact::DisplayInfo& /*rDisplayInfo*/,
1859 bool /*bEdit*/)
1861 // this will be handled in the application if needed
1862 return true;
1865 // DrawContact support: Methods for handling Page changes
1866 void SdrPage::ActionChanged() const
1868 // Do necessary ViewContact actions
1869 GetViewContact().ActionChanged();
1871 // #i48535# also handle MasterPage change
1872 if(TRG_HasMasterPage())
1874 TRG_GetMasterPageDescriptorViewContact().ActionChanged();
1878 //////////////////////////////////////////////////////////////////////////////
1879 // sdr::Comment interface
1881 const SdrPageProperties* SdrPage::getCorrectSdrPageProperties() const
1883 if(mpMasterPageDescriptor)
1885 return mpMasterPageDescriptor->getCorrectSdrPageProperties();
1887 else
1889 return &getSdrPageProperties();
1893 //////////////////////////////////////////////////////////////////////////////
1894 // use new redirector instead of pPaintProc
1896 StandardCheckVisisbilityRedirector::StandardCheckVisisbilityRedirector()
1897 : ViewObjectContactRedirector()
1901 StandardCheckVisisbilityRedirector::~StandardCheckVisisbilityRedirector()
1905 drawinglayer::primitive2d::Primitive2DSequence StandardCheckVisisbilityRedirector::createRedirectedPrimitive2DSequence(
1906 const sdr::contact::ViewObjectContact& rOriginal,
1907 const sdr::contact::DisplayInfo& rDisplayInfo)
1909 SdrObject* pObject = rOriginal.GetViewContact().TryToGetSdrObject();
1911 if(pObject)
1913 if(pObject->GetPage())
1915 if(pObject->GetPage()->checkVisibility(rOriginal, rDisplayInfo, false))
1917 return ::sdr::contact::ViewObjectContactRedirector::createRedirectedPrimitive2DSequence(rOriginal, rDisplayInfo);
1921 return drawinglayer::primitive2d::Primitive2DSequence();
1923 else
1925 // not an object, maybe a page
1926 return ::sdr::contact::ViewObjectContactRedirector::createRedirectedPrimitive2DSequence(rOriginal, rDisplayInfo);
1931 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */