tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / sd / source / ui / sidebar / MasterPageContainerProviders.hxx
blob672644a9f6b222bd4f80f1e47c45c77ce1b0ddae
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 <rtl/ustring.hxx>
23 #include <sfx2/objsh.hxx>
25 class Image;
26 class SdDrawDocument;
27 class SdPage;
28 namespace sd
30 class PreviewRenderer;
32 namespace sd
34 class DrawDocShell;
37 namespace sd::sidebar
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
44 public:
45 /** Return a master page either by returning an already existing one, by
46 creating a new page, or by loading a document.
47 @param pDocument
48 The document of the MasterPageContainer. It may be used to
49 create new pages.
51 virtual SdPage* operator()(SdDrawDocument* pDocument) = 0;
53 /** An abstract value for the expected cost of providing a master page
54 object.
55 @return
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;
62 protected:
63 ~PageObjectProvider() {}
66 class PreviewProvider
68 public:
69 /** Create a preview image in the specified width.
70 @param nWidth
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.
74 @param pPage
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.)
78 @param rRenderer
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
92 preview.
94 virtual bool NeedsPageObject() = 0;
96 protected:
97 ~PreviewProvider() {}
100 /** Provide previews of existing page objects by rendering them.
102 class PagePreviewProvider : public PreviewProvider
104 public:
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;
111 private:
114 /** Provide master page objects for template documents for which only the
115 URL is given.
117 class TemplatePageObjectProvider : public PageObjectProvider
119 public:
120 explicit TemplatePageObjectProvider(OUString sURL);
121 virtual ~TemplatePageObjectProvider(){};
122 virtual SdPage* operator()(SdDrawDocument* pDocument) override;
123 virtual int GetCostIndex() override;
125 private:
126 OUString msURL;
127 SfxObjectShellLock mxDocumentShell;
128 ::sd::DrawDocShell* LoadDocument(const OUString& sFileName);
131 /** Provide previews for template documents by loading the thumbnails from
132 the documents.
134 class TemplatePreviewProvider : public PreviewProvider
136 public:
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;
143 private:
144 OUString msURL;
147 /** Create an empty default master page.
149 class DefaultPageObjectProvider : public PageObjectProvider
151 public:
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
163 public:
164 explicit ExistingPageProvider(SdPage* pPage);
165 virtual ~ExistingPageProvider() {}
166 virtual SdPage* operator()(SdDrawDocument* pDocument) override;
167 virtual int GetCostIndex() override;
169 private:
170 SdPage* mpPage;
173 } // end of namespace sd::sidebar
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */