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 INCLUDED_SD_SOURCE_UI_SIDEBAR_MASTERPAGECONTAINERPROVIDERS_HXX
21 : #define INCLUDED_SD_SOURCE_UI_SIDEBAR_MASTERPAGECONTAINERPROVIDERS_HXX
22 :
23 : #include <rtl/ustring.hxx>
24 : #include <sfx2/objsh.hxx>
25 :
26 : class Image;
27 : class SdDrawDocument;
28 : class SdPage;
29 : namespace sd { class PreviewRenderer; }
30 : namespace sd { class DrawDocShell; }
31 :
32 : namespace sd { namespace sidebar {
33 :
34 : /** Interface for a provider of page objects. It is used by the
35 : MasterPageDescriptor to create master page objects on demand.
36 : */
37 0 : class PageObjectProvider
38 : {
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.
45 : */
46 : virtual SdPage* operator() (SdDrawDocument* pDocument) = 0;
47 :
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.
54 : */
55 : virtual int GetCostIndex() = 0;
56 :
57 : virtual bool operator== (const PageObjectProvider& rProvider) = 0;
58 :
59 : protected:
60 0 : ~PageObjectProvider() {}
61 : };
62 :
63 0 : class PreviewProvider
64 : {
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.
78 : */
79 : virtual Image operator() (int nWidth, SdPage* pPage, ::sd::PreviewRenderer& rRenderer) = 0;
80 :
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.
85 : */
86 : virtual int GetCostIndex() = 0;
87 :
88 : /** Return whether the page object passed is necessary to create a
89 : preview.
90 : */
91 : virtual bool NeedsPageObject() = 0;
92 :
93 : protected:
94 0 : ~PreviewProvider() {}
95 : };
96 :
97 : /** Provide previews of existing page objects by rendering them.
98 : */
99 : class PagePreviewProvider : public PreviewProvider
100 : {
101 : public:
102 : PagePreviewProvider();
103 0 : 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:
108 : };
109 :
110 : /** Provide master page objects for template documents for which only the
111 : URL is given.
112 : */
113 : class TemplatePageObjectProvider : public PageObjectProvider
114 : {
115 : public:
116 : TemplatePageObjectProvider (const OUString& rsURL);
117 0 : 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);
125 : };
126 :
127 : /** Provide previews for template documents by loading the thumbnails from
128 : the documents.
129 : */
130 : class TemplatePreviewProvider : public PreviewProvider
131 : {
132 : public:
133 : TemplatePreviewProvider (const OUString& rsURL);
134 0 : 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;
140 : };
141 :
142 : /** Create an empty default master page.
143 : */
144 : class DefaultPageObjectProvider : public PageObjectProvider
145 : {
146 : public:
147 : DefaultPageObjectProvider();
148 0 : 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;
152 : };
153 :
154 : /** This implementation of the PageObjectProvider simply returns an already
155 : existing master page object.
156 : */
157 : class ExistingPageProvider : public PageObjectProvider
158 : {
159 : public:
160 : ExistingPageProvider (SdPage* pPage);
161 0 : 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;
167 : };
168 :
169 : } } // end of namespace sd::sidebar
170 :
171 : #endif
172 :
173 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|