Get the style color and number just once
[LibreOffice.git] / sd / source / ui / sidebar / MasterPageDescriptor.hxx
blob24e77e65bda48914a6a1d2456f27444af65e946f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #pragma once
22 #include "MasterPageContainer.hxx"
23 #include <memory>
25 namespace sd { class PreviewRenderer; }
26 class SdDrawDocument;
28 namespace sd::sidebar {
30 class PageObjectProvider;
31 class PreviewProvider;
33 class MasterPageDescriptor;
34 typedef std::shared_ptr<MasterPageDescriptor> SharedMasterPageDescriptor;
36 /** A collection of data that is stored for every master page in the
37 MasterpageContainer.
39 class MasterPageDescriptor
41 public:
42 MasterPageDescriptor (
43 MasterPageContainer::Origin eOrigin,
44 const sal_Int32 nTemplateIndex,
45 std::u16string_view rURL,
46 OUString sPageName,
47 OUString sStyleName,
48 const bool bIsPrecious,
49 std::shared_ptr<PageObjectProvider> pPageObjectProvider,
50 std::shared_ptr<PreviewProvider> pPreviewProvider);
52 void SetToken (MasterPageContainer::Token aToken);
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.
62 ::std::unique_ptr<std::vector<MasterPageContainerChangeEvent::EventType> >
63 Update (
64 const MasterPageDescriptor& rDescriptor);
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.
72 const Image& GetPreview (MasterPageContainer::PreviewSize ePreviewSize) const;
74 /** Use the PreviewProvider to get access to a preview of the master
75 page.
77 Note that this is only done, when either bForce is <TRUE/> or
78 the PreviewProvider::GetCostIndex() returns 0.
80 The small preview is created by scaling the large one, not by
81 calling PreviewProvider::operator() a second time.
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/>.
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.
103 bool UpdatePreview (
104 sal_Int32 nCostThreshold,
105 const Size& rSmallSize,
106 const Size& rLargeSize,
107 ::sd::PreviewRenderer& rRenderer);
109 /** Use the PageObjectProvider to get access to the master page object.
111 Note that this is only done, when either bForce is <TRUE/> or the
112 PreviewProvider::GetCostIndex() returns 0.
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.
127 int UpdatePageObject (
128 sal_Int32 nCostThreshold,
129 SdDrawDocument* pDocument);
131 enum URLClassification {
132 URLCLASS_USER,
133 URLCLASS_LAYOUT,
134 URLCLASS_PRESENTATION,
135 URLCLASS_OTHER,
136 URLCLASS_UNKNOWN,
137 URLCLASS_UNDETERMINED
140 URLClassification GetURLClassification();
142 /** The Token under which the MasterPageContainer gives access to the
143 object.
145 MasterPageContainer::Token maToken;
147 /** A rough specification of the origin of the master page.
149 MasterPageContainer::Origin meOrigin;
151 /** The URL is not empty for master pages loaded from a template
152 document.
154 OUString msURL;
156 /** Taken from the title of the template file.
158 OUString msPageName;
160 /** Taken from the master page object.
162 OUString msStyleName;
164 const bool mbIsPrecious;
166 /** The actual master page.
168 SdPage* mpMasterPage;
170 /** A slide that uses the master page.
172 SdPage* mpSlide;
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.
178 Image maSmallPreview;
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.
183 Image maLargePreview;
185 /** The preview provider. May be empty. May be replaced during the
186 lifetime of a MasterPageDescriptor object.
188 std::shared_ptr<PreviewProvider> mpPreviewProvider;
190 /** The master page provider. May be empty. May be replaced during
191 the lifetime of a MasterPageDescriptor object.
193 std::shared_ptr<PageObjectProvider> mpPageObjectProvider;
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.
199 sal_Int32 mnTemplateIndex;
201 URLClassification meURLClassification;
203 sal_Int32 mnUseCount;
205 class URLComparator { public:
206 OUString msURL;
207 explicit URLComparator (OUString sURL);
208 bool operator() (const SharedMasterPageDescriptor& rDescriptor);
210 class StyleNameComparator { public:
211 OUString msStyleName;
212 explicit StyleNameComparator (OUString sStyleName);
213 bool operator() (const SharedMasterPageDescriptor& rDescriptor);
215 class PageObjectComparator { public:
216 const SdPage* mpMasterPage;
217 explicit PageObjectComparator (const SdPage* pPageObject);
218 bool operator() (const SharedMasterPageDescriptor& rDescriptor);
220 class AllComparator { public:
221 explicit AllComparator(SharedMasterPageDescriptor aDescriptor);
222 bool operator() (const SharedMasterPageDescriptor& rDescriptor);
223 private:
224 SharedMasterPageDescriptor mpDescriptor;
229 } // end of namespace sd::sidebar
231 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */