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 #ifndef SD_SIDEBAR_PANELS_MASTER_PAGE_DESCRIPTOR_HXX
23 #define SD_SIDEBAR_PANELS_MASTER_PAGE_DESCRIPTOR_HXX
24 
25 #include "MasterPageContainer.hxx"
26 #include <boost/shared_ptr.hpp>
27 
28 namespace sd { namespace sidebar {
29 
30 class PageObjectProvider;
31 class PreviewProvider;
32 
33 class MasterPageDescriptor;
34 typedef ::boost::shared_ptr<MasterPageDescriptor> SharedMasterPageDescriptor;
35 
36 /** A collection of data that is stored for every master page in the
37     MasterpageContainer.
38 */
39 class MasterPageDescriptor
40 {
41 public:
42     MasterPageDescriptor (
43         MasterPageContainer::Origin eOrigin,
44         const sal_Int32 nTemplateIndex,
45         const String& rURL,
46         const String& rPageName,
47         const String& rStyleName,
48         const bool bIsPrecious,
49         const ::boost::shared_ptr<PageObjectProvider>& rpPageObjectProvider,
50         const ::boost::shared_ptr<PreviewProvider>& rpPreviewProvider);
51     MasterPageDescriptor (const MasterPageDescriptor& rDescriptor);
52     ~MasterPageDescriptor (void);
53 
54     void SetToken (MasterPageContainer::Token aToken);
55 
56     /** Update the called MasterPageDescriptor object with values from the
57         given one.  Only those values are updated that have default values
58         in the called object and that have non-default values in the given
59         one.
60         @return
61             Returns a list of event types for which event notifications have
62             to be sent to listeners.  The list may be empty or NULL.
63     */
64     ::std::auto_ptr<std::vector<MasterPageContainerChangeEvent::EventType> >
65         Update (
66             const MasterPageDescriptor& rDescriptor);
67 
68     /** This convenience method returns either a small or a large preview,
69         depending on the given size specifier.
70         Note that the previews are not created when they are not present.
71         @return
72             The returned preview may be empty.
73     */
74     Image GetPreview (MasterPageContainer::PreviewSize ePreviewSize);
75 
76     /** Use the PreviewProvider to get access to a preview of the master
77         page.
78 
79         Note that this is only done, when either bForce is <TRUE/> or
80         the PreviewProvider::GetCostIndex() returns 0.
81 
82         The small preview is created by scaling the large one, not by
83         calling PreviewProvider::operator() a second time.
84 
85         It is the responsibility of the caller to call UpdatePageObject()
86         before calling this method  when the PreviewProvider can only work
87         when the master page object is present, i.e. its NeedsPageObject()
88         method returns <TRUE/>.
89 
90         @param nCostThreshold
91             When this is zero or positive then the preview is created only
92             when the preview provider has a cost equal to or smaller than
93             this threshold.  A negative value forces the preview to be
94             created, regardless of the cost.
95         @param rSmallSize
96             Size of the small preview.
97         @param rLargeSize
98             Size of the large preview.
99         @param rRenderer
100             A PreviewRenderer object that may be used to create a preview.
101         @return
102             When the previews are successfully provided then <TRUE/> is
103             returned.
104     */
105     bool UpdatePreview (
106         sal_Int32 nCostThreshold,
107         const Size& rSmallSize,
108         const Size& rLargeSize,
109         ::sd::PreviewRenderer& rRenderer);
110 
111     /** Use the PageObjectProvider to get access to the master page object.
112 
113         Note that this is only done, when either bForce is <TRUE/> or the
114         PreviewProvider::GetCostIndex() returns 0.
115 
116         @param nCostThreshold
117             When this is zero or positive then the page object is created
118             only when the page object provider has a cost equal to or
119             smaller than this threshold.  A negative value forces the
120             page object be created, regardless of the cost.
121         @param pDocument
122             This document of the MasterPageContainer may be used to create
123             a page object with or store one in.
124         @return
125             When the master page object is successfully provided then
126             <TRUE/> is returned.
127     */
128     bool UpdatePageObject (
129         sal_Int32 nCostThreshold,
130         SdDrawDocument* pDocument);
131 
132     enum URLClassification {
133         URLCLASS_USER,
134         URLCLASS_LAYOUT,
135         URLCLASS_PRESENTATION,
136         URLCLASS_OTHER,
137         URLCLASS_UNKNOWN,
138         URLCLASS_UNDETERMINED
139     };
140 
141     URLClassification GetURLClassification (void);
142 
143     /** The Token under which the MasterPageContainer gives access to the
144         object.
145     */
146     MasterPageContainer::Token maToken;
147 
148     /** A rough specification of the origin of the master page.
149     */
150     MasterPageContainer::Origin meOrigin;
151 
152     /** The URL is not empty for master pages loaded from a template
153         document.
154     */
155     ::rtl::OUString msURL;
156 
157     /** Taken from the title of the template file.
158     */
159     ::rtl::OUString msPageName;
160 
161     /** Taken from the master page object.
162     */
163     ::rtl::OUString msStyleName;
164 
165     const bool mbIsPrecious;
166 
167     /** The actual master page.
168     */
169     SdPage* mpMasterPage;
170 
171     /** A slide that uses the master page.
172     */
173     SdPage* mpSlide;
174 
175     /** A small (the default size) preview of the master page.  May be
176         empty.  When this smaller preview is not empty then the larger one
177         is not empty, too.
178     */
179     Image maSmallPreview;
180 
181     /** A large preview of the master page.  May be empty.  When this larger
182         preview is not empty then the smaller one is not empty, too.
183     */
184     Image maLargePreview;
185 
186     /** The prewview provider. May be empty.  May be replaced during the
187         lifetime of a MasterPageDescriptor object.
188     */
189     ::boost::shared_ptr<PreviewProvider> mpPreviewProvider;
190 
191     /** The master page provider.  May be empty.  May be replaced during
192         the lifetime of a MasterPageDescriptor object.
193     */
194     ::boost::shared_ptr<PageObjectProvider> mpPageObjectProvider;
195 
196     /** This index represents the order in which templates are provided via
197         the TemplateScanner.  It defines the order in which the entries in
198         the AllMasterPagesSelector are displayed.  The default value is -1.
199     */
200     sal_Int32 mnTemplateIndex;
201 
202     URLClassification meURLClassification;
203 
204     sal_Int32 mnUseCount;
205 
206     class URLComparator { public:
207         ::rtl::OUString msURL;
208         URLComparator (const ::rtl::OUString& sURL);
209         bool operator() (const SharedMasterPageDescriptor& rDescriptor);
210     };
211     class StyleNameComparator { public:
212         ::rtl::OUString msStyleName;
213         StyleNameComparator (const ::rtl::OUString& sStyleName);
214         bool operator() (const SharedMasterPageDescriptor& rDescriptor);
215     };
216     class PageObjectComparator { public:
217         const SdPage* mpMasterPage;
218         PageObjectComparator (const SdPage* pPageObject);
219         bool operator() (const SharedMasterPageDescriptor& rDescriptor);
220     };
221     class AllComparator { public:
222         AllComparator(const SharedMasterPageDescriptor& rDescriptor);
223         bool operator() (const SharedMasterPageDescriptor& rDescriptor);
224     private:
225         SharedMasterPageDescriptor mpDescriptor;
226     };
227 
228 
229 };
230 
231 
232 } } // end of namespace sd::sidebar
233 
234 #endif
235