bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / sidebar / MasterPageContainerProviders.hxx
blobbffab9c3270c4a754554d17f91f120527599beaf
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 #ifndef INCLUDED_SD_SOURCE_UI_SIDEBAR_MASTERPAGECONTAINERPROVIDERS_HXX
21 #define INCLUDED_SD_SOURCE_UI_SIDEBAR_MASTERPAGECONTAINERPROVIDERS_HXX
23 #include <rtl/ustring.hxx>
24 #include <sfx2/objsh.hxx>
26 class Image;
27 class SdDrawDocument;
28 class SdPage;
29 namespace sd { class PreviewRenderer; }
30 namespace sd { class DrawDocShell; }
32 namespace sd { namespace sidebar {
34 /** Interface for a provider of page objects. It is used by the
35 MasterPageDescriptor to create master page objects on demand.
37 class PageObjectProvider
39 public:
40 /** Return a master page either by returning an already existing one, by
41 creating a new page, or by loading a document.
42 @param pDocument
43 The document of the MasterPageContainer. It may be used to
44 create new pages.
46 virtual SdPage* operator() (SdDrawDocument* pDocument) = 0;
48 /** An abstract value for the expected cost of providing a master page
49 object.
50 @return
51 A value of 0 represents for the lowest cost, i.e. an almost
52 immediate return. Positive values stand for higher costs.
53 Negative values are not supported.
55 virtual int GetCostIndex() = 0;
57 virtual bool operator== (const PageObjectProvider& rProvider) = 0;
59 protected:
60 ~PageObjectProvider() {}
63 class PreviewProvider
65 public:
66 /** Create a preview image in the specified width.
67 @param nWidth
68 Requested width of the preview. The calling method can cope
69 with other sizes as well but the resulting image quality is
70 better when the returned image has the requested size.
71 @param pPage
72 Page object for which a preview is requested. This may be NULL
73 when the page object is expensive to get and the PreviewProvider
74 does not need this object (NeedsPageObject() returns false.)
75 @param rRenderer
76 This PreviewRenderer may be used by the PreviewProvider to
77 create a preview image.
79 virtual Image operator() (int nWidth, SdPage* pPage, ::sd::PreviewRenderer& rRenderer) = 0;
81 /** Return a value that indicates how expensive the creation of a
82 preview image is. The higher the returned value the more expensive
83 is the preview creation. Return 0 when the preview is already
84 present and can be returned immediately.
86 virtual int GetCostIndex() = 0;
88 /** Return whether the page object passed is necessary to create a
89 preview.
91 virtual bool NeedsPageObject() = 0;
93 protected:
94 ~PreviewProvider() {}
97 /** Provide previews of existing page objects by rendering them.
99 class PagePreviewProvider : public PreviewProvider
101 public:
102 PagePreviewProvider();
103 virtual ~PagePreviewProvider() {}
104 virtual Image operator () (int nWidth, SdPage* pPage, ::sd::PreviewRenderer& rRenderer) SAL_OVERRIDE;
105 virtual int GetCostIndex() SAL_OVERRIDE;
106 virtual bool NeedsPageObject() SAL_OVERRIDE;
107 private:
110 /** Provide master page objects for template documents for which only the
111 URL is given.
113 class TemplatePageObjectProvider : public PageObjectProvider
115 public:
116 TemplatePageObjectProvider (const OUString& rsURL);
117 virtual ~TemplatePageObjectProvider() {};
118 virtual SdPage* operator () (SdDrawDocument* pDocument) SAL_OVERRIDE;
119 virtual int GetCostIndex() SAL_OVERRIDE;
120 virtual bool operator== (const PageObjectProvider& rProvider) SAL_OVERRIDE;
121 private:
122 OUString msURL;
123 SfxObjectShellLock mxDocumentShell;
124 ::sd::DrawDocShell* LoadDocument (const OUString& sFileName);
127 /** Provide previews for template documents by loading the thumbnails from
128 the documents.
130 class TemplatePreviewProvider : public PreviewProvider
132 public:
133 TemplatePreviewProvider (const OUString& rsURL);
134 virtual ~TemplatePreviewProvider() {};
135 virtual Image operator() (int nWidth, SdPage* pPage, ::sd::PreviewRenderer& rRenderer) SAL_OVERRIDE;
136 virtual int GetCostIndex() SAL_OVERRIDE;
137 virtual bool NeedsPageObject() SAL_OVERRIDE;
138 private:
139 OUString msURL;
142 /** Create an empty default master page.
144 class DefaultPageObjectProvider : public PageObjectProvider
146 public:
147 DefaultPageObjectProvider();
148 virtual ~DefaultPageObjectProvider() {}
149 virtual SdPage* operator () (SdDrawDocument* pDocument) SAL_OVERRIDE;
150 virtual int GetCostIndex() SAL_OVERRIDE;
151 virtual bool operator== (const PageObjectProvider& rProvider) SAL_OVERRIDE;
154 /** This implementation of the PageObjectProvider simply returns an already
155 existing master page object.
157 class ExistingPageProvider : public PageObjectProvider
159 public:
160 ExistingPageProvider (SdPage* pPage);
161 virtual ~ExistingPageProvider() {}
162 virtual SdPage* operator() (SdDrawDocument* pDocument) SAL_OVERRIDE;
163 virtual int GetCostIndex() SAL_OVERRIDE;
164 virtual bool operator== (const PageObjectProvider& rProvider) SAL_OVERRIDE;
165 private:
166 SdPage* mpPage;
169 } } // end of namespace sd::sidebar
171 #endif
173 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */