Coverage Report

Created: 2026-06-30 11:14

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