LibreOffice Module sd (master) 1
MasterPageContainerProviders.cxx
Go to the documentation of this file.
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
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>
30#include <utility>
31#include <vcl/image.hxx>
33#include <sal/log.hxx>
34
35using namespace ::com::sun::star;
36using namespace ::com::sun::star::uno;
37
38namespace sd::sidebar {
39
40//===== PagePreviewProvider ===================================================
41
43{
44}
45
47 int nWidth,
48 SdPage* pPage,
49 ::sd::PreviewRenderer& rRenderer)
50{
51 Image aPreview;
52
53 if (pPage != nullptr)
54 {
55 // Use the given renderer to create a preview of the given page
56 // object.
57 aPreview = rRenderer.RenderPage(
58 pPage,
59 nWidth);
60 }
61
62 return aPreview;
63}
64
66{
67 return 5;
68}
69
71{
72 return true;
73}
74
75//===== TemplatePreviewProvider ===============================================
76
78 : msURL(std::move(sURL))
79{
80}
81
83 int,
84 SdPage*,
86{
88}
89
91{
92 return 10;
93}
94
96{
97 return false;
98}
99
100//===== TemplatePageObjectProvider =============================================
101
103 : msURL(std::move(sURL))
104{
105}
106
108{
109 SdPage* pPage = nullptr;
110
111 mxDocumentShell = nullptr;
112 try
113 {
114 // Load the template document and return its first page.
115 ::sd::DrawDocShell* pDocumentShell = LoadDocument (msURL);
116 if (pDocumentShell != nullptr)
117 {
118 SdDrawDocument* pDocument = pDocumentShell->GetDoc();
119 if (pDocument != nullptr)
120 {
121 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 if (pPage != nullptr)
126 pPage->SetPrecious(false);
127 }
128 }
129 }
130 catch (const uno::RuntimeException&)
131 {
133 pPage = nullptr;
134 }
135
136 return pPage;
137}
138
140{
141 SfxApplication* pSfxApp = SfxGetpApp();
142 std::unique_ptr<SfxItemSet> pSet(new SfxAllItemSet (pSfxApp->GetPool()));
143 pSet->Put (SfxBoolItem (SID_TEMPLATE, true));
144 pSet->Put (SfxBoolItem (SID_PREVIEW, true));
145 if (pSfxApp->LoadTemplate (mxDocumentShell, sFileName, std::move(pSet)))
146 {
147 mxDocumentShell = nullptr;
148 }
150 return dynamic_cast< ::sd::DrawDocShell *>( pShell );
151}
152
154{
155 return 20;
156}
157
158//===== DefaultPageObjectProvider ==============================================
159
161{
162}
163
165{
166 SdPage* pLocalMasterPage = nullptr;
167 if (pContainerDocument != nullptr)
168 {
169 SdPage* pLocalSlide = pContainerDocument->GetSdPage(0, PageKind::Standard);
170 if (pLocalSlide!=nullptr && pLocalSlide->TRG_HasMasterPage())
171 pLocalMasterPage = dynamic_cast<SdPage*>(&pLocalSlide->TRG_GetMasterPage());
172 }
173
174 if (pLocalMasterPage == nullptr)
175 {
176 SAL_WARN( "sd", "can not create master page for slide");
177 }
178
179 return pLocalMasterPage;
180}
181
183{
184 return 15;
185}
186
187//===== ExistingPageProvider ==================================================
188
190 : mpPage(pPage)
191{
192}
193
195{
196 return mpPage;
197}
198
200{
201 return 0;
202}
203
204} // end of namespace sd::sidebar
205
206/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
FPDF_PAGE mpPage
SfxApplication * SfxGetpApp()
SdPage * GetSdPage(sal_uInt16 nPgNum, PageKind ePgKind) const
Definition: drawdoc2.cxx:207
SdPage * GetMasterSdPage(sal_uInt16 nPgNum, PageKind ePgKind)
Definition: drawdoc2.cxx:217
void SetPrecious(const bool bIsPrecious)
Set the "precious" flag to the given value.
Definition: sdpage.cxx:3112
SdrPage & TRG_GetMasterPage() const
bool TRG_HasMasterPage() const
ErrCode LoadTemplate(SfxObjectShellLock &xDoc, const OUString &rFileName, std::unique_ptr< SfxItemSet > pArgs)
SfxItemPool & GetPool() const
static BitmapEx readThumbnail(const OUString &msURL)
SdDrawDocument * GetDoc()
Image RenderPage(const SdPage *pPage, const sal_Int32 nWidth)
Render a page with the given pixel size.
virtual SdPage * operator()(SdDrawDocument *pDocument) override
Return a master page either by returning an already existing one, by creating a new page,...
virtual int GetCostIndex() override
An abstract value for the expected cost of providing a master page object.
virtual SdPage * operator()(SdDrawDocument *pDocument) override
Return a master page either by returning an already existing one, by creating a new page,...
virtual int GetCostIndex() override
An abstract value for the expected cost of providing a master page object.
virtual bool NeedsPageObject() override
Return whether the page object passed is necessary to create a preview.
virtual int GetCostIndex() override
Return a value that indicates how expensive the creation of a preview image is.
virtual Image operator()(int nWidth, SdPage *pPage, ::sd::PreviewRenderer &rRenderer) override
Create a preview image in the specified width.
::sd::DrawDocShell * LoadDocument(const OUString &sFileName)
virtual SdPage * operator()(SdDrawDocument *pDocument) override
Return a master page either by returning an already existing one, by creating a new page,...
virtual int GetCostIndex() override
An abstract value for the expected cost of providing a master page object.
virtual Image operator()(int nWidth, SdPage *pPage, ::sd::PreviewRenderer &rRenderer) override
Create a preview image in the specified width.
virtual int GetCostIndex() override
Return a value that indicates how expensive the creation of a preview image is.
virtual bool NeedsPageObject() override
Return whether the page object passed is necessary to create a preview.
#define DBG_UNHANDLED_EXCEPTION(...)
#define SAL_WARN(area, stream)