xref: /AOO41X/main/svx/source/svdraw/sdrmasterpagedescriptor.cxx (revision f6e50924346d0b8c0b07c91832a97665dd718b0c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 #include <svx/sdrmasterpagedescriptor.hxx>
27 #include <svx/sdr/contact/viewcontactofmasterpagedescriptor.hxx>
28 #include <svx/svdpage.hxx>
29 
30 // #i42075#
31 #include <svx/svdobj.hxx>
32 #include <svx/xfillit0.hxx>
33 #include <svl/itemset.hxx>
34 
35 //////////////////////////////////////////////////////////////////////////////
36 
37 namespace sdr
38 {
39     // ViewContact part
CreateObjectSpecificViewContact()40     sdr::contact::ViewContact* MasterPageDescriptor::CreateObjectSpecificViewContact()
41     {
42         return new sdr::contact::ViewContactOfMasterPageDescriptor(*this);
43     }
44 
MasterPageDescriptor(SdrPage & aOwnerPage,SdrPage & aUsedPage)45     MasterPageDescriptor::MasterPageDescriptor(SdrPage& aOwnerPage, SdrPage& aUsedPage)
46     :   maOwnerPage(aOwnerPage),
47         maUsedPage(aUsedPage),
48         mpViewContact(0L)
49     {
50         // all layers visible
51         maVisibleLayers.SetAll();
52 
53         // register at used page
54         maUsedPage.AddPageUser(*this);
55     }
56 
~MasterPageDescriptor()57     MasterPageDescriptor::~MasterPageDescriptor()
58     {
59         // de-register at used page
60         maUsedPage.RemovePageUser(*this);
61 
62         if(mpViewContact)
63         {
64             delete mpViewContact;
65             mpViewContact = 0L;
66         }
67     }
68 
69     // ViewContact part
GetViewContact() const70     sdr::contact::ViewContact& MasterPageDescriptor::GetViewContact() const
71     {
72         if(!mpViewContact)
73         {
74             const_cast< MasterPageDescriptor* >(this)->mpViewContact =
75                 const_cast< MasterPageDescriptor* >(this)->CreateObjectSpecificViewContact();
76         }
77 
78         return *mpViewContact;
79     }
80 
81     // this method is called form the destructor of the referenced page.
82     // do all necessary action to forget the page. It is not necessary to call
83     // RemovePageUser(), that is done form the destructor.
PageInDestruction(const SdrPage &)84     void MasterPageDescriptor::PageInDestruction(const SdrPage& /*rPage*/)
85     {
86         maOwnerPage.TRG_ClearMasterPage();
87     }
88 
SetVisibleLayers(const SetOfByte & rNew)89     void MasterPageDescriptor::SetVisibleLayers(const SetOfByte& rNew)
90     {
91         if(rNew != maVisibleLayers)
92         {
93             maVisibleLayers = rNew;
94             GetViewContact().ActionChanged();
95         }
96     }
97 
98     // operators
operator ==(const MasterPageDescriptor & rCandidate) const99     sal_Bool MasterPageDescriptor::operator==(const MasterPageDescriptor& rCandidate) const
100     {
101         return (&maOwnerPage == &rCandidate.maOwnerPage
102             && &maUsedPage == &rCandidate.maUsedPage
103             && maVisibleLayers == rCandidate.maVisibleLayers);
104     }
105 
operator !=(const MasterPageDescriptor & rCandidate) const106     sal_Bool MasterPageDescriptor::operator!=(const MasterPageDescriptor& rCandidate) const
107     {
108         return (&maOwnerPage != &rCandidate.maOwnerPage
109             || &maUsedPage != &rCandidate.maUsedPage
110             || maVisibleLayers != rCandidate.maVisibleLayers);
111     }
112 
getCorrectSdrPageProperties() const113     const SdrPageProperties* MasterPageDescriptor::getCorrectSdrPageProperties() const
114     {
115         const SdrPage* pCorrectPage = &GetOwnerPage();
116         const SdrPageProperties* pCorrectProperties = &pCorrectPage->getSdrPageProperties();
117 
118         if(XFILL_NONE == ((const XFillStyleItem&)pCorrectProperties->GetItemSet().Get(XATTR_FILLSTYLE)).GetValue())
119         {
120             pCorrectPage = &GetUsedPage();
121             pCorrectProperties = &pCorrectPage->getSdrPageProperties();
122         }
123 
124         if(pCorrectPage->IsMasterPage() && !pCorrectProperties->GetStyleSheet())
125         {
126             // #i110846# Suppress SdrPage FillStyle for MasterPages without StyleSheets,
127             // else the PoolDefault (XFILL_COLOR and Blue8) will be used. Normally, all
128             // MasterPages should have a StyleSheet excactly for this reason, but historically
129             // e.g. the Notes MasterPage has no StyleSheet set (and there maybe others).
130             pCorrectProperties = 0;
131         }
132 
133         return pCorrectProperties;
134     }
135 } // end of namespace sdr
136 
137 //////////////////////////////////////////////////////////////////////////////
138 // eof
139