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