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 :
33 : namespace sd { namespace sidebar {
34 :
35 :
36 : /** Interface for a provider of page objects. It is used by the
37 : MasterPageDescriptor to create master page objects on demand.
38 : */
39 0 : class PageObjectProvider
40 : {
41 : public:
42 : /** Return a master page either by returning an already existing one, by
43 : creating a new page, or by loading a document.
44 : @param pDocument
45 : The document of the MasterPageContainer. It may be used to
46 : create new pages.
47 : */
48 : virtual SdPage* operator() (SdDrawDocument* pDocument) = 0;
49 :
50 : /** An abstract value for the expected cost of providing a master page
51 : object.
52 : @return
53 : A value of 0 represents for the lowest cost, i.e. an almost
54 : immediate return. Positive values stand for higher costs.
55 : Negative values are not supported.
56 : */
57 : virtual int GetCostIndex (void) = 0;
58 :
59 : virtual bool operator== (const PageObjectProvider& rProvider) = 0;
60 :
61 : protected:
62 0 : ~PageObjectProvider() {}
63 : };
64 :
65 :
66 :
67 :
68 0 : class PreviewProvider
69 : {
70 : public:
71 : /** Create a preview image in the specified width.
72 : @param nWidth
73 : Requested width of the preview. The calling method can cope
74 : with other sizes as well but the resulting image quality is
75 : better when the returned image has the requested size.
76 : @param pPage
77 : Page object for which a preview is requested. This may be NULL
78 : when the page object is expensive to get and the PreviewProvider
79 : does not need this object (NeedsPageObject() returns false.)
80 : @param rRenderer
81 : This PreviewRenderer may be used by the PreviewProvider to
82 : create a preview image.
83 : */
84 : virtual Image operator() (int nWidth, SdPage* pPage, ::sd::PreviewRenderer& rRenderer) = 0;
85 :
86 : /** Return a value that indicates how expensive the creation of a
87 : preview image is. The higher the returned value the more expensive
88 : is the preview creation. Return 0 when the preview is already
89 : present and can be returned immediately.
90 : */
91 : virtual int GetCostIndex (void) = 0;
92 :
93 : /** Return whether the page object passed is necessary to create a
94 : preview.
95 : */
96 : virtual bool NeedsPageObject (void) = 0;
97 :
98 : protected:
99 0 : ~PreviewProvider() {}
100 : };
101 :
102 :
103 :
104 :
105 : /** Provide previews of existing page objects by rendering them.
106 : */
107 : class PagePreviewProvider : public PreviewProvider
108 : {
109 : public:
110 : PagePreviewProvider (void);
111 0 : virtual ~PagePreviewProvider() {}
112 : virtual Image operator () (int nWidth, SdPage* pPage, ::sd::PreviewRenderer& rRenderer) SAL_OVERRIDE;
113 : virtual int GetCostIndex (void) SAL_OVERRIDE;
114 : virtual bool NeedsPageObject (void) SAL_OVERRIDE;
115 : private:
116 : };
117 :
118 :
119 :
120 :
121 : /** Provide master page objects for template documents for which only the
122 : URL is given.
123 : */
124 : class TemplatePageObjectProvider : public PageObjectProvider
125 : {
126 : public:
127 : TemplatePageObjectProvider (const OUString& rsURL);
128 0 : virtual ~TemplatePageObjectProvider (void) {};
129 : virtual SdPage* operator () (SdDrawDocument* pDocument) SAL_OVERRIDE;
130 : virtual int GetCostIndex (void) SAL_OVERRIDE;
131 : virtual bool operator== (const PageObjectProvider& rProvider) SAL_OVERRIDE;
132 : private:
133 : OUString msURL;
134 : SfxObjectShellLock mxDocumentShell;
135 : ::sd::DrawDocShell* LoadDocument (const OUString& sFileName);
136 : };
137 :
138 :
139 :
140 :
141 : /** Provide previews for template documents by loading the thumbnails from
142 : the documents.
143 : */
144 : class TemplatePreviewProvider : public PreviewProvider
145 : {
146 : public:
147 : TemplatePreviewProvider (const OUString& rsURL);
148 0 : virtual ~TemplatePreviewProvider (void) {};
149 : virtual Image operator() (int nWidth, SdPage* pPage, ::sd::PreviewRenderer& rRenderer) SAL_OVERRIDE;
150 : virtual int GetCostIndex (void) SAL_OVERRIDE;
151 : virtual bool NeedsPageObject (void) SAL_OVERRIDE;
152 : private:
153 : OUString msURL;
154 : };
155 :
156 :
157 :
158 :
159 : /** Create an empty default master page.
160 : */
161 : class DefaultPageObjectProvider : public PageObjectProvider
162 : {
163 : public:
164 : DefaultPageObjectProvider (void);
165 0 : virtual ~DefaultPageObjectProvider() {}
166 : virtual SdPage* operator () (SdDrawDocument* pDocument) SAL_OVERRIDE;
167 : virtual int GetCostIndex (void) SAL_OVERRIDE;
168 : virtual bool operator== (const PageObjectProvider& rProvider) SAL_OVERRIDE;
169 : };
170 :
171 :
172 :
173 : /** This implementation of the PageObjectProvider simply returns an already
174 : existing master page object.
175 : */
176 : class ExistingPageProvider : public PageObjectProvider
177 : {
178 : public:
179 : ExistingPageProvider (SdPage* pPage);
180 0 : virtual ~ExistingPageProvider() {}
181 : virtual SdPage* operator() (SdDrawDocument* pDocument) SAL_OVERRIDE;
182 : virtual int GetCostIndex (void) SAL_OVERRIDE;
183 : virtual bool operator== (const PageObjectProvider& rProvider) SAL_OVERRIDE;
184 : private:
185 : SdPage* mpPage;
186 : };
187 :
188 : } } // end of namespace sd::sidebar
189 :
190 : #endif
191 :
192 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|