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