Update ooo320-m1
[ooovba.git] / svx / source / svdraw / sdrmasterpagedescriptor.cxx
blobbefbc27f980958b3b465a0877a3614cf140beb52
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sdrmasterpagedescriptor.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include <svx/sdrmasterpagedescriptor.hxx>
34 #include <svx/sdr/contact/viewcontactofmasterpagedescriptor.hxx>
35 #include <svx/svdpage.hxx>
37 // #i42075#
38 #include <svx/svdobj.hxx>
40 //////////////////////////////////////////////////////////////////////////////
42 namespace sdr
44 // ViewContact part
45 sdr::contact::ViewContact* MasterPageDescriptor::CreateObjectSpecificViewContact()
47 return new sdr::contact::ViewContactOfMasterPageDescriptor(*this);
50 MasterPageDescriptor::MasterPageDescriptor(SdrPage& aOwnerPage, SdrPage& aUsedPage)
51 : maOwnerPage(aOwnerPage),
52 maUsedPage(aUsedPage),
53 mpViewContact(0L)
55 // all layers visible
56 maVisibleLayers.SetAll();
58 // register at used page
59 maUsedPage.AddPageUser(*this);
62 MasterPageDescriptor::~MasterPageDescriptor()
64 // de-register at used page
65 maUsedPage.RemovePageUser(*this);
67 if(mpViewContact)
69 delete mpViewContact;
70 mpViewContact = 0L;
74 // ViewContact part
75 sdr::contact::ViewContact& MasterPageDescriptor::GetViewContact() const
77 if(!mpViewContact)
79 ((MasterPageDescriptor*)this)->mpViewContact = ((MasterPageDescriptor*)this)->CreateObjectSpecificViewContact();
82 return *mpViewContact;
85 // this method is called form the destructor of the referenced page.
86 // do all necessary action to forget the page. It is not necessary to call
87 // RemovePageUser(), that is done form the destructor.
88 void MasterPageDescriptor::PageInDestruction(const SdrPage& /*rPage*/)
90 maOwnerPage.TRG_ClearMasterPage();
93 void MasterPageDescriptor::SetVisibleLayers(const SetOfByte& rNew)
95 if(rNew != maVisibleLayers)
97 maVisibleLayers = rNew;
98 GetViewContact().ActionChanged();
100 // #i42075# For AFs convenience, do a change notify at the MasterPageBackgroundObject, too
101 SdrObject* pObject = GetBackgroundObject();
103 if(pObject)
105 pObject->BroadcastObjectChange();
110 // operators
111 sal_Bool MasterPageDescriptor::operator==(const MasterPageDescriptor& rCandidate) const
113 return (&maOwnerPage == &rCandidate.maOwnerPage
114 && &maUsedPage == &rCandidate.maUsedPage
115 && maVisibleLayers == rCandidate.maVisibleLayers);
118 sal_Bool MasterPageDescriptor::operator!=(const MasterPageDescriptor& rCandidate) const
120 return (&maOwnerPage != &rCandidate.maOwnerPage
121 || &maUsedPage != &rCandidate.maUsedPage
122 || maVisibleLayers != rCandidate.maVisibleLayers);
125 // #i42075# Get the correct BackgroundObject
126 SdrObject* MasterPageDescriptor::GetBackgroundObject() const
128 SdrObject* pRetval = 0L;
129 const SdrPage& rMasterPage = GetUsedPage();
131 // Here i will rely on old knowledge about the 0'st element of a masterpage
132 // being the PageBackgroundObject. This will be removed again when that definition
133 // will be changed.
134 #ifdef DBG_UTIL
135 const sal_uInt32 nMasterPageObjectCount(rMasterPage.GetObjCount());
136 DBG_ASSERT(1 <= nMasterPageObjectCount,
137 "MasterPageDescriptor::GetBackgroundObject(): MasterPageBackgroundObject missing (!)");
138 #endif
139 pRetval = rMasterPage.GetObj(0L);
141 // Test if it's really what we need. There are known problems where
142 // the 0th object is not the MasterPageBackgroundObject at all.
143 if(pRetval && !pRetval->IsMasterPageBackgroundObject())
145 pRetval = 0L;
148 // Get the evtl. existing page background object from the using page and use it
149 // preferred to the MasterPageBackgroundObject
150 const SdrPage& rOwnerPage = GetOwnerPage();
151 SdrObject* pCandidate = rOwnerPage.GetBackgroundObj();
153 if(pCandidate)
155 pRetval = pCandidate;
158 return pRetval;
160 } // end of namespace sdr
162 //////////////////////////////////////////////////////////////////////////////
163 // eof