1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 #ifndef SD_SIDEBAR_PANELS_MASTER_PAGE_CONTAINER_PROVIDERS_HXX 23 #define SD_SIDEBAR_PANELS_MASTER_PAGE_CONTAINER_PROVIDERS_HXX 24 25 #include <rtl/ustring.hxx> 26 #include <sfx2/objsh.hxx> 27 28 class Image; 29 class SdDrawDocument; 30 class SdPage; 31 namespace sd { class PreviewRenderer; } 32 namespace sd { class DrawDocShell; } 33 34 35 namespace sd { namespace sidebar { 36 37 38 /** Interface for a provider of page objects. It is used by the 39 MasterPageDescriptor to create master page objects on demand. 40 */ 41 class PageObjectProvider 42 { 43 public: 44 /** Return a master page either by returning an already existing one, by 45 creating a new page, or by loading a document. 46 @param pDocument 47 The document of the MasterPageContainer. It may be used to 48 create new pages. 49 */ 50 virtual SdPage* operator() (SdDrawDocument* pDocument) = 0; 51 52 /** An abstract value for the expected cost of providing a master page 53 object. 54 @return 55 A value of 0 represents for the lowest cost, i.e. an almost 56 immediate return. Positive values stand for higher costs. 57 Negative values are not supported. 58 */ 59 virtual int GetCostIndex (void) = 0; 60 61 virtual bool operator== (const PageObjectProvider& rProvider) = 0; 62 }; 63 64 65 66 67 class PreviewProvider 68 { 69 public: 70 /** Create a preview image in the specified width. 71 @param nWidth 72 Requested width of the preview. The calling method can cope 73 with other sizes as well but the resulting image quality is 74 better when the returned image has the requested size. 75 @param pPage 76 Page object for which a preview is requested. This may be NULL 77 when the page object is expensive to get and the PreviewProvider 78 does not need this object (NeedsPageObject() returns false.) 79 @param rRenderer 80 This PreviewRenderer may be used by the PreviewProvider to 81 create a preview image. 82 */ 83 virtual Image operator() (int nWidth, SdPage* pPage, ::sd::PreviewRenderer& rRenderer) = 0; 84 85 /** Return a value that indicates how expensive the creation of a 86 preview image is. The higher the returned value the more expensive 87 is the preview creation. Return 0 when the preview is already 88 present and can be returned immediately. 89 */ 90 virtual int GetCostIndex (void) = 0; 91 92 /** Return whether the page object passed is necessary to create a 93 preview. 94 */ 95 virtual bool NeedsPageObject (void) = 0; 96 }; 97 98 99 100 101 /** Provide previews of existing page objects by rendering them. 102 */ 103 class PagePreviewProvider : public PreviewProvider 104 { 105 public: 106 PagePreviewProvider (void); 107 virtual Image operator () (int nWidth, SdPage* pPage, ::sd::PreviewRenderer& rRenderer); 108 virtual int GetCostIndex (void); 109 virtual bool NeedsPageObject (void); 110 private: 111 }; 112 113 114 115 116 /** Provide master page objects for template documents for which only the 117 URL is given. 118 */ 119 class TemplatePageObjectProvider : public PageObjectProvider 120 { 121 public: 122 TemplatePageObjectProvider (const ::rtl::OUString& rsURL); ~TemplatePageObjectProvider(void)123 virtual ~TemplatePageObjectProvider (void) {}; 124 virtual SdPage* operator () (SdDrawDocument* pDocument); 125 virtual int GetCostIndex (void); 126 virtual bool operator== (const PageObjectProvider& rProvider); 127 private: 128 ::rtl::OUString msURL; 129 SfxObjectShellLock mxDocumentShell; 130 ::sd::DrawDocShell* LoadDocument (const ::rtl::OUString& sFileName); 131 }; 132 133 134 135 136 /** Provide previews for template documents by loading the thumbnails from 137 the documents. 138 */ 139 class TemplatePreviewProvider : public PreviewProvider 140 { 141 public: 142 TemplatePreviewProvider (const ::rtl::OUString& rsURL); ~TemplatePreviewProvider(void)143 virtual ~TemplatePreviewProvider (void) {}; 144 virtual Image operator() (int nWidth, SdPage* pPage, ::sd::PreviewRenderer& rRenderer); 145 virtual int GetCostIndex (void); 146 virtual bool NeedsPageObject (void); 147 private: 148 ::rtl::OUString msURL; 149 }; 150 151 152 153 154 /** Create an empty default master page. 155 */ 156 class DefaultPageObjectProvider : public PageObjectProvider 157 { 158 public: 159 DefaultPageObjectProvider (void); 160 virtual SdPage* operator () (SdDrawDocument* pDocument); 161 virtual int GetCostIndex (void); 162 virtual bool operator== (const PageObjectProvider& rProvider); 163 }; 164 165 166 167 /** This implementation of the PageObjectProvider simply returns an already 168 existing master page object. 169 */ 170 class ExistingPageProvider : public PageObjectProvider 171 { 172 public: 173 ExistingPageProvider (SdPage* pPage); 174 virtual SdPage* operator() (SdDrawDocument* pDocument); 175 virtual int GetCostIndex (void); 176 virtual bool operator== (const PageObjectProvider& rProvider); 177 private: 178 SdPage* mpPage; 179 }; 180 181 } } // end of namespace sd::sidebar 182 183 #endif 184