Coverage Report

Created: 2026-02-14 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sd/source/ui/sidebar/MasterPageContainerProviders.cxx
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
#include "MasterPageContainerProviders.hxx"
21
22
#include <DrawDocShell.hxx>
23
#include <drawdoc.hxx>
24
#include <sdpage.hxx>
25
#include <PreviewRenderer.hxx>
26
#include <svl/eitem.hxx>
27
#include <sfx2/app.hxx>
28
#include <sfx2/sfxsids.hrc>
29
#include <sfx2/thumbnailview.hxx>
30
#include <utility>
31
#include <vcl/image.hxx>
32
#include <comphelper/diagnose_ex.hxx>
33
#include <sal/log.hxx>
34
35
using namespace ::com::sun::star;
36
using namespace ::com::sun::star::uno;
37
38
namespace sd::sidebar {
39
40
//===== PagePreviewProvider ===================================================
41
42
PagePreviewProvider::PagePreviewProvider()
43
0
{
44
0
}
45
46
Image PagePreviewProvider::operator () (
47
    int nWidth,
48
    SdPage* pPage,
49
    ::sd::PreviewRenderer& rRenderer)
50
0
{
51
0
    Image aPreview;
52
53
0
    if (pPage != nullptr)
54
0
    {
55
        // Use the given renderer to create a preview of the given page
56
        // object.
57
0
        aPreview = rRenderer.RenderPage(
58
0
            pPage,
59
0
            nWidth);
60
0
    }
61
62
0
    return aPreview;
63
0
}
64
65
int PagePreviewProvider::GetCostIndex()
66
0
{
67
0
    return 5;
68
0
}
69
70
bool PagePreviewProvider::NeedsPageObject()
71
0
{
72
0
    return true;
73
0
}
74
75
//===== TemplatePreviewProvider ===============================================
76
77
TemplatePreviewProvider::TemplatePreviewProvider (OUString sURL)
78
0
    : msURL(std::move(sURL))
79
0
{
80
0
}
81
82
Image TemplatePreviewProvider::operator() (
83
    int,
84
    SdPage*,
85
    ::sd::PreviewRenderer&)
86
0
{
87
0
    return Image(ThumbnailView::readThumbnail(msURL));
88
0
}
89
90
int TemplatePreviewProvider::GetCostIndex()
91
0
{
92
0
    return 10;
93
0
}
94
95
bool TemplatePreviewProvider::NeedsPageObject()
96
0
{
97
0
    return false;
98
0
}
99
100
//===== TemplatePageObjectProvider =============================================
101
102
TemplatePageObjectProvider::TemplatePageObjectProvider (OUString sURL)
103
0
    : msURL(std::move(sURL))
104
0
{
105
0
}
106
107
SdPage* TemplatePageObjectProvider::operator() (SdDrawDocument*)
108
0
{
109
0
    SdPage* pPage = nullptr;
110
111
0
    mxDocumentShell = nullptr;
112
0
    try
113
0
    {
114
        // Load the template document and return its first page.
115
0
        ::sd::DrawDocShell* pDocumentShell = LoadDocument (msURL);
116
0
        if (pDocumentShell != nullptr)
117
0
        {
118
0
            SdDrawDocument* pDocument = pDocumentShell->GetDoc();
119
0
            if (pDocument != nullptr)
120
0
            {
121
0
                pPage = pDocument->GetMasterSdPage(0, PageKind::Standard);
122
                // In order to make the newly loaded master page deletable
123
                // when copied into documents it is marked as no "precious".
124
                // When it is modified then it is marked as "precious".
125
0
                if (pPage != nullptr)
126
0
                    pPage->SetPrecious(false);
127
0
            }
128
0
        }
129
0
    }
130
0
    catch (const uno::RuntimeException&)
131
0
    {
132
0
        DBG_UNHANDLED_EXCEPTION("sd");
133
0
        pPage = nullptr;
134
0
    }
135
136
0
    return pPage;
137
0
}
138
139
::sd::DrawDocShell* TemplatePageObjectProvider::LoadDocument (const OUString& sFileName)
140
0
{
141
0
    SfxApplication* pSfxApp = SfxGetpApp();
142
0
    std::unique_ptr<SfxItemSet> pSet(new SfxAllItemSet (pSfxApp->GetPool()));
143
0
    pSet->Put (SfxBoolItem (SID_TEMPLATE, true));
144
0
    pSet->Put (SfxBoolItem (SID_PREVIEW, true));
145
0
    if (pSfxApp->LoadTemplate (mxDocumentShell, sFileName, std::move(pSet)))
146
0
    {
147
0
        mxDocumentShell = nullptr;
148
0
    }
149
0
    SfxObjectShell* pShell = mxDocumentShell;
150
0
    return dynamic_cast< ::sd::DrawDocShell *>( pShell );
151
0
}
152
153
int TemplatePageObjectProvider::GetCostIndex()
154
0
{
155
0
    return 20;
156
0
}
157
158
//===== DefaultPageObjectProvider ==============================================
159
160
DefaultPageObjectProvider::DefaultPageObjectProvider()
161
0
{
162
0
}
163
164
SdPage* DefaultPageObjectProvider::operator () (SdDrawDocument* pContainerDocument)
165
0
{
166
0
    SdPage* pLocalMasterPage = nullptr;
167
0
    if (pContainerDocument != nullptr)
168
0
    {
169
0
        SdPage* pLocalSlide = pContainerDocument->GetSdPage(0, PageKind::Standard);
170
0
        if (pLocalSlide!=nullptr && pLocalSlide->TRG_HasMasterPage())
171
0
            pLocalMasterPage = dynamic_cast<SdPage*>(&pLocalSlide->TRG_GetMasterPage());
172
0
    }
173
174
0
    if (pLocalMasterPage == nullptr)
175
0
    {
176
0
        SAL_WARN( "sd", "can not create master page for slide");
177
0
    }
178
179
0
    return pLocalMasterPage;
180
0
}
181
182
int DefaultPageObjectProvider::GetCostIndex()
183
0
{
184
0
    return 15;
185
0
}
186
187
//===== ExistingPageProvider ==================================================
188
189
ExistingPageProvider::ExistingPageProvider (SdPage* pPage)
190
0
    : mpPage(pPage)
191
0
{
192
0
}
193
194
SdPage* ExistingPageProvider::operator() (SdDrawDocument*)
195
0
{
196
0
    return mpPage;
197
0
}
198
199
int ExistingPageProvider::GetCostIndex()
200
0
{
201
0
    return 0;
202
0
}
203
204
} // end of namespace sd::sidebar
205
206
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */