1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include <rtl/ustring.hxx>
23 #include <sfx2/objsh.hxx>
30 class PreviewRenderer
;
39 /** Interface for a provider of page objects. It is used by the
40 MasterPageDescriptor to create master page objects on demand.
42 class PageObjectProvider
45 /** Return a master page either by returning an already existing one, by
46 creating a new page, or by loading a document.
48 The document of the MasterPageContainer. It may be used to
51 virtual SdPage
* operator()(SdDrawDocument
* pDocument
) = 0;
53 /** An abstract value for the expected cost of providing a master page
56 A value of 0 represents for the lowest cost, i.e. an almost
57 immediate return. Positive values stand for higher costs.
58 Negative values are not supported.
60 virtual int GetCostIndex() = 0;
63 ~PageObjectProvider() {}
69 /** Create a preview image in the specified width.
71 Requested width of the preview. The calling method can cope
72 with other sizes as well but the resulting image quality is
73 better when the returned image has the requested size.
75 Page object for which a preview is requested. This may be NULL
76 when the page object is expensive to get and the PreviewProvider
77 does not need this object (NeedsPageObject() returns false.)
79 This PreviewRenderer may be used by the PreviewProvider to
80 create a preview image.
82 virtual Image
operator()(int nWidth
, SdPage
* pPage
, ::sd::PreviewRenderer
& rRenderer
) = 0;
84 /** Return a value that indicates how expensive the creation of a
85 preview image is. The higher the returned value the more expensive
86 is the preview creation. Return 0 when the preview is already
87 present and can be returned immediately.
89 virtual int GetCostIndex() = 0;
91 /** Return whether the page object passed is necessary to create a
94 virtual bool NeedsPageObject() = 0;
100 /** Provide previews of existing page objects by rendering them.
102 class PagePreviewProvider
: public PreviewProvider
105 PagePreviewProvider();
106 virtual ~PagePreviewProvider() {}
107 virtual Image
operator()(int nWidth
, SdPage
* pPage
, ::sd::PreviewRenderer
& rRenderer
) override
;
108 virtual int GetCostIndex() override
;
109 virtual bool NeedsPageObject() override
;
114 /** Provide master page objects for template documents for which only the
117 class TemplatePageObjectProvider
: public PageObjectProvider
120 explicit TemplatePageObjectProvider(OUString sURL
);
121 virtual ~TemplatePageObjectProvider(){};
122 virtual SdPage
* operator()(SdDrawDocument
* pDocument
) override
;
123 virtual int GetCostIndex() override
;
127 SfxObjectShellLock mxDocumentShell
;
128 ::sd::DrawDocShell
* LoadDocument(const OUString
& sFileName
);
131 /** Provide previews for template documents by loading the thumbnails from
134 class TemplatePreviewProvider
: public PreviewProvider
137 explicit TemplatePreviewProvider(OUString sURL
);
138 virtual ~TemplatePreviewProvider(){};
139 virtual Image
operator()(int nWidth
, SdPage
* pPage
, ::sd::PreviewRenderer
& rRenderer
) override
;
140 virtual int GetCostIndex() override
;
141 virtual bool NeedsPageObject() override
;
147 /** Create an empty default master page.
149 class DefaultPageObjectProvider
: public PageObjectProvider
152 DefaultPageObjectProvider();
153 virtual ~DefaultPageObjectProvider() {}
154 virtual SdPage
* operator()(SdDrawDocument
* pDocument
) override
;
155 virtual int GetCostIndex() override
;
158 /** This implementation of the PageObjectProvider simply returns an already
159 existing master page object.
161 class ExistingPageProvider
: public PageObjectProvider
164 explicit ExistingPageProvider(SdPage
* pPage
);
165 virtual ~ExistingPageProvider() {}
166 virtual SdPage
* operator()(SdDrawDocument
* pDocument
) override
;
167 virtual int GetCostIndex() override
;
173 } // end of namespace sd::sidebar
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */