LibreOffice Module sd (master)
1
sd
source
ui
sidebar
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
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
{
44
}
45
46
Image
PagePreviewProvider::operator ()
(
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
65
int
PagePreviewProvider::GetCostIndex
()
66
{
67
return
5;
68
}
69
70
bool
PagePreviewProvider::NeedsPageObject
()
71
{
72
return
true
;
73
}
74
75
//===== TemplatePreviewProvider ===============================================
76
77
TemplatePreviewProvider::TemplatePreviewProvider
(OUString sURL)
78
: msURL(
std
::move(sURL))
79
{
80
}
81
82
Image
TemplatePreviewProvider::operator()
(
83
int
,
84
SdPage
*,
85
::sd::PreviewRenderer
&)
86
{
87
return
Image
(
ThumbnailView::readThumbnail
(
msURL
));
88
}
89
90
int
TemplatePreviewProvider::GetCostIndex
()
91
{
92
return
10;
93
}
94
95
bool
TemplatePreviewProvider::NeedsPageObject
()
96
{
97
return
false
;
98
}
99
100
//===== TemplatePageObjectProvider =============================================
101
102
TemplatePageObjectProvider::TemplatePageObjectProvider
(OUString sURL)
103
: msURL(
std
::move(sURL))
104
{
105
}
106
107
SdPage
*
TemplatePageObjectProvider::operator()
(
SdDrawDocument
*)
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
{
132
DBG_UNHANDLED_EXCEPTION
(
"sd"
);
133
pPage =
nullptr
;
134
}
135
136
return
pPage;
137
}
138
139
::sd::DrawDocShell
*
TemplatePageObjectProvider::LoadDocument
(
const
OUString& sFileName)
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
}
149
SfxObjectShell
* pShell =
mxDocumentShell
;
150
return
dynamic_cast<
::
sd::DrawDocShell
*
>
( pShell );
151
}
152
153
int
TemplatePageObjectProvider::GetCostIndex
()
154
{
155
return
20;
156
}
157
158
//===== DefaultPageObjectProvider ==============================================
159
160
DefaultPageObjectProvider::DefaultPageObjectProvider
()
161
{
162
}
163
164
SdPage
*
DefaultPageObjectProvider::operator ()
(
SdDrawDocument
* pContainerDocument)
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
182
int
DefaultPageObjectProvider::GetCostIndex
()
183
{
184
return
15;
185
}
186
187
//===== ExistingPageProvider ==================================================
188
189
ExistingPageProvider::ExistingPageProvider
(
SdPage
* pPage)
190
:
mpPage
(pPage)
191
{
192
}
193
194
SdPage
*
ExistingPageProvider::operator()
(
SdDrawDocument
*)
195
{
196
return
mpPage
;
197
}
198
199
int
ExistingPageProvider::GetCostIndex
()
200
{
201
return
0;
202
}
203
204
}
// end of namespace sd::sidebar
205
206
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
DrawDocShell.hxx
MasterPageContainerProviders.hxx
mpPage
FPDF_PAGE mpPage
PreviewRenderer.hxx
app.hxx
SfxGetpApp
SfxApplication * SfxGetpApp()
Image
SdDrawDocument
Definition:
drawdoc.hxx:121
SdDrawDocument::GetSdPage
SdPage * GetSdPage(sal_uInt16 nPgNum, PageKind ePgKind) const
Definition:
drawdoc2.cxx:207
SdDrawDocument::GetMasterSdPage
SdPage * GetMasterSdPage(sal_uInt16 nPgNum, PageKind ePgKind)
Definition:
drawdoc2.cxx:217
SdPage
Definition:
sdpage.hxx:93
SdPage::SetPrecious
void SetPrecious(const bool bIsPrecious)
Set the "precious" flag to the given value.
Definition:
sdpage.cxx:3112
SdrPage::TRG_GetMasterPage
SdrPage & TRG_GetMasterPage() const
SdrPage::TRG_HasMasterPage
bool TRG_HasMasterPage() const
SfxAllItemSet
SfxApplication
SfxApplication::LoadTemplate
ErrCode LoadTemplate(SfxObjectShellLock &xDoc, const OUString &rFileName, std::unique_ptr< SfxItemSet > pArgs)
SfxBoolItem
SfxObjectShell
SfxShell::GetPool
SfxItemPool & GetPool() const
ThumbnailView::readThumbnail
static BitmapEx readThumbnail(const OUString &msURL)
sd::DrawDocShell
Definition:
DrawDocShell.hxx:48
sd::DrawDocShell::GetDoc
SdDrawDocument * GetDoc()
Definition:
DrawDocShell.hxx:109
sd::PreviewRenderer
Definition:
PreviewRenderer.hxx:37
sd::PreviewRenderer::RenderPage
Image RenderPage(const SdPage *pPage, const sal_Int32 nWidth)
Render a page with the given pixel size.
Definition:
PreviewRenderer.cxx:84
sd::sidebar::DefaultPageObjectProvider::DefaultPageObjectProvider
DefaultPageObjectProvider()
Definition:
MasterPageContainerProviders.cxx:160
sd::sidebar::DefaultPageObjectProvider::operator()
virtual SdPage * operator()(SdDrawDocument *pDocument) override
Return a master page either by returning an already existing one, by creating a new page,...
Definition:
MasterPageContainerProviders.cxx:164
sd::sidebar::DefaultPageObjectProvider::GetCostIndex
virtual int GetCostIndex() override
An abstract value for the expected cost of providing a master page object.
Definition:
MasterPageContainerProviders.cxx:182
sd::sidebar::ExistingPageProvider::operator()
virtual SdPage * operator()(SdDrawDocument *pDocument) override
Return a master page either by returning an already existing one, by creating a new page,...
Definition:
MasterPageContainerProviders.cxx:194
sd::sidebar::ExistingPageProvider::GetCostIndex
virtual int GetCostIndex() override
An abstract value for the expected cost of providing a master page object.
Definition:
MasterPageContainerProviders.cxx:199
sd::sidebar::ExistingPageProvider::mpPage
SdPage * mpPage
Definition:
MasterPageContainerProviders.hxx:170
sd::sidebar::ExistingPageProvider::ExistingPageProvider
ExistingPageProvider(SdPage *pPage)
Definition:
MasterPageContainerProviders.cxx:189
sd::sidebar::PagePreviewProvider::NeedsPageObject
virtual bool NeedsPageObject() override
Return whether the page object passed is necessary to create a preview.
Definition:
MasterPageContainerProviders.cxx:70
sd::sidebar::PagePreviewProvider::GetCostIndex
virtual int GetCostIndex() override
Return a value that indicates how expensive the creation of a preview image is.
Definition:
MasterPageContainerProviders.cxx:65
sd::sidebar::PagePreviewProvider::PagePreviewProvider
PagePreviewProvider()
Definition:
MasterPageContainerProviders.cxx:42
sd::sidebar::PagePreviewProvider::operator()
virtual Image operator()(int nWidth, SdPage *pPage, ::sd::PreviewRenderer &rRenderer) override
Create a preview image in the specified width.
Definition:
MasterPageContainerProviders.cxx:46
sd::sidebar::TemplatePageObjectProvider::LoadDocument
::sd::DrawDocShell * LoadDocument(const OUString &sFileName)
Definition:
MasterPageContainerProviders.cxx:139
sd::sidebar::TemplatePageObjectProvider::operator()
virtual SdPage * operator()(SdDrawDocument *pDocument) override
Return a master page either by returning an already existing one, by creating a new page,...
Definition:
MasterPageContainerProviders.cxx:107
sd::sidebar::TemplatePageObjectProvider::mxDocumentShell
SfxObjectShellLock mxDocumentShell
Definition:
MasterPageContainerProviders.hxx:127
sd::sidebar::TemplatePageObjectProvider::TemplatePageObjectProvider
TemplatePageObjectProvider(OUString sURL)
Definition:
MasterPageContainerProviders.cxx:102
sd::sidebar::TemplatePageObjectProvider::GetCostIndex
virtual int GetCostIndex() override
An abstract value for the expected cost of providing a master page object.
Definition:
MasterPageContainerProviders.cxx:153
sd::sidebar::TemplatePageObjectProvider::msURL
OUString msURL
Definition:
MasterPageContainerProviders.hxx:126
sd::sidebar::TemplatePreviewProvider::TemplatePreviewProvider
TemplatePreviewProvider(OUString sURL)
Definition:
MasterPageContainerProviders.cxx:77
sd::sidebar::TemplatePreviewProvider::msURL
OUString msURL
Definition:
MasterPageContainerProviders.hxx:144
sd::sidebar::TemplatePreviewProvider::operator()
virtual Image operator()(int nWidth, SdPage *pPage, ::sd::PreviewRenderer &rRenderer) override
Create a preview image in the specified width.
Definition:
MasterPageContainerProviders.cxx:82
sd::sidebar::TemplatePreviewProvider::GetCostIndex
virtual int GetCostIndex() override
Return a value that indicates how expensive the creation of a preview image is.
Definition:
MasterPageContainerProviders.cxx:90
sd::sidebar::TemplatePreviewProvider::NeedsPageObject
virtual bool NeedsPageObject() override
Return whether the page object passed is necessary to create a preview.
Definition:
MasterPageContainerProviders.cxx:95
diagnose_ex.hxx
DBG_UNHANDLED_EXCEPTION
#define DBG_UNHANDLED_EXCEPTION(...)
eitem.hxx
image.hxx
log.hxx
SAL_WARN
#define SAL_WARN(area, stream)
com::sun::star::uno
com::sun::star
sd::sidebar
Definition:
AllMasterPagesSelector.cxx:68
std
PageKind::Standard
@ Standard
sdpage.hxx
thumbnailview.hxx
Generated on Sun Jul 30 2023 04:27:23 for LibreOffice Module sd (master) by
1.9.3