xref: /trunk/main/svx/source/svdraw/sdrmasterpagedescriptor.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svx.hxx"
30 #include <svx/sdrmasterpagedescriptor.hxx>
31 #include <svx/sdr/contact/viewcontactofmasterpagedescriptor.hxx>
32 #include <svx/svdpage.hxx>
33 
34 // #i42075#
35 #include <svx/svdobj.hxx>
36 #include <svx/xfillit0.hxx>
37 #include <svl/itemset.hxx>
38 
39 //////////////////////////////////////////////////////////////////////////////
40 
41 namespace sdr
42 {
43     // ViewContact part
44     sdr::contact::ViewContact* MasterPageDescriptor::CreateObjectSpecificViewContact()
45     {
46         return new sdr::contact::ViewContactOfMasterPageDescriptor(*this);
47     }
48 
49     MasterPageDescriptor::MasterPageDescriptor(SdrPage& aOwnerPage, SdrPage& aUsedPage)
50     :   maOwnerPage(aOwnerPage),
51         maUsedPage(aUsedPage),
52         mpViewContact(0L)
53     {
54         // all layers visible
55         maVisibleLayers.SetAll();
56 
57         // register at used page
58         maUsedPage.AddPageUser(*this);
59     }
60 
61     MasterPageDescriptor::~MasterPageDescriptor()
62     {
63         // de-register at used page
64         maUsedPage.RemovePageUser(*this);
65 
66         if(mpViewContact)
67         {
68             delete mpViewContact;
69             mpViewContact = 0L;
70         }
71     }
72 
73     // ViewContact part
74     sdr::contact::ViewContact& MasterPageDescriptor::GetViewContact() const
75     {
76         if(!mpViewContact)
77         {
78             const_cast< MasterPageDescriptor* >(this)->mpViewContact =
79                 const_cast< MasterPageDescriptor* >(this)->CreateObjectSpecificViewContact();
80         }
81 
82         return *mpViewContact;
83     }
84 
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*/)
89     {
90         maOwnerPage.TRG_ClearMasterPage();
91     }
92 
93     void MasterPageDescriptor::SetVisibleLayers(const SetOfByte& rNew)
94     {
95         if(rNew != maVisibleLayers)
96         {
97             maVisibleLayers = rNew;
98             GetViewContact().ActionChanged();
99         }
100     }
101 
102     // operators
103     sal_Bool MasterPageDescriptor::operator==(const MasterPageDescriptor& rCandidate) const
104     {
105         return (&maOwnerPage == &rCandidate.maOwnerPage
106             && &maUsedPage == &rCandidate.maUsedPage
107             && maVisibleLayers == rCandidate.maVisibleLayers);
108     }
109 
110     sal_Bool MasterPageDescriptor::operator!=(const MasterPageDescriptor& rCandidate) const
111     {
112         return (&maOwnerPage != &rCandidate.maOwnerPage
113             || &maUsedPage != &rCandidate.maUsedPage
114             || maVisibleLayers != rCandidate.maVisibleLayers);
115     }
116 
117     const SdrPageProperties* MasterPageDescriptor::getCorrectSdrPageProperties() const
118     {
119         const SdrPage* pCorrectPage = &GetOwnerPage();
120         const SdrPageProperties* pCorrectProperties = &pCorrectPage->getSdrPageProperties();
121 
122         if(XFILL_NONE == ((const XFillStyleItem&)pCorrectProperties->GetItemSet().Get(XATTR_FILLSTYLE)).GetValue())
123         {
124             pCorrectPage = &GetUsedPage();
125             pCorrectProperties = &pCorrectPage->getSdrPageProperties();
126         }
127 
128         if(pCorrectPage->IsMasterPage() && !pCorrectProperties->GetStyleSheet())
129         {
130             // #i110846# Suppress SdrPage FillStyle for MasterPages without StyleSheets,
131             // else the PoolDefault (XFILL_COLOR and Blue8) will be used. Normally, all
132             // MasterPages should have a StyleSheet excactly for this reason, but historically
133             // e.g. the Notes MasterPage has no StyleSheet set (and there maybe others).
134             pCorrectProperties = 0;
135         }
136 
137         return pCorrectProperties;
138     }
139 } // end of namespace sdr
140 
141 //////////////////////////////////////////////////////////////////////////////
142 // eof
143