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