1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "MasterPageContainerProviders.hxx"
22 #include <DrawDocShell.hxx>
23 #include <drawdoc.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 <vcl/image.hxx>
31 #include <com/sun/star/embed/ElementModes.hpp>
32 #include <com/sun/star/embed/StorageFactory.hpp>
33 #include <tools/diagnose_ex.h>
34 #include <sal/log.hxx>
36 using namespace ::com::sun::star
;
37 using namespace ::com::sun::star::uno
;
39 namespace sd
{ namespace sidebar
{
41 //===== PagePreviewProvider ===================================================
43 PagePreviewProvider::PagePreviewProvider()
47 Image
PagePreviewProvider::operator () (
50 ::sd::PreviewRenderer
& rRenderer
)
56 // Use the given renderer to create a preview of the given page
58 aPreview
= rRenderer
.RenderPage(
66 int PagePreviewProvider::GetCostIndex()
71 bool PagePreviewProvider::NeedsPageObject()
76 //===== TemplatePreviewProvider ===============================================
78 TemplatePreviewProvider::TemplatePreviewProvider (const OUString
& rsURL
)
83 Image
TemplatePreviewProvider::operator() (
86 ::sd::PreviewRenderer
&)
88 return Image(ThumbnailView::readThumbnail(msURL
));
91 int TemplatePreviewProvider::GetCostIndex()
96 bool TemplatePreviewProvider::NeedsPageObject()
101 //===== TemplatePageObjectProvider =============================================
103 TemplatePageObjectProvider::TemplatePageObjectProvider (const OUString
& rsURL
)
109 SdPage
* TemplatePageObjectProvider::operator() (SdDrawDocument
*)
111 SdPage
* pPage
= nullptr;
113 mxDocumentShell
= nullptr;
114 ::sd::DrawDocShell
* pDocumentShell
= nullptr;
117 // Load the template document and return its first page.
118 pDocumentShell
= LoadDocument (msURL
);
119 if (pDocumentShell
!= nullptr)
121 SdDrawDocument
* pDocument
= pDocumentShell
->GetDoc();
122 if (pDocument
!= nullptr)
124 pPage
= pDocument
->GetMasterSdPage(0, PageKind::Standard
);
125 // In order to make the newly loaded master page deletable
126 // when copied into documents it is marked as no "precious".
127 // When it is modified then it is marked as "precious".
128 if (pPage
!= nullptr)
129 pPage
->SetPrecious(false);
133 catch (const uno::RuntimeException
&)
135 DBG_UNHANDLED_EXCEPTION("sd");
142 ::sd::DrawDocShell
* TemplatePageObjectProvider::LoadDocument (const OUString
& sFileName
)
144 SfxApplication
* pSfxApp
= SfxGetpApp();
145 std::unique_ptr
<SfxItemSet
> pSet(new SfxAllItemSet (pSfxApp
->GetPool()));
146 pSet
->Put (SfxBoolItem (SID_TEMPLATE
, true));
147 pSet
->Put (SfxBoolItem (SID_PREVIEW
, true));
148 if (pSfxApp
->LoadTemplate (mxDocumentShell
, sFileName
, std::move(pSet
)))
150 mxDocumentShell
= nullptr;
152 SfxObjectShell
* pShell
= mxDocumentShell
;
153 return dynamic_cast< ::sd::DrawDocShell
*>( pShell
);
156 int TemplatePageObjectProvider::GetCostIndex()
161 //===== DefaultPageObjectProvider ==============================================
163 DefaultPageObjectProvider::DefaultPageObjectProvider()
167 SdPage
* DefaultPageObjectProvider::operator () (SdDrawDocument
* pContainerDocument
)
169 SdPage
* pLocalMasterPage
= nullptr;
170 if (pContainerDocument
!= nullptr)
172 SdPage
* pLocalSlide
= pContainerDocument
->GetSdPage(0, PageKind::Standard
);
173 if (pLocalSlide
!=nullptr && pLocalSlide
->TRG_HasMasterPage())
174 pLocalMasterPage
= dynamic_cast<SdPage
*>(&pLocalSlide
->TRG_GetMasterPage());
177 if (pLocalMasterPage
== nullptr)
179 SAL_WARN( "sd", "can not create master page for slide");
182 return pLocalMasterPage
;
185 int DefaultPageObjectProvider::GetCostIndex()
190 //===== ExistingPageProvider ==================================================
192 ExistingPageProvider::ExistingPageProvider (SdPage
* pPage
)
197 SdPage
* ExistingPageProvider::operator() (SdDrawDocument
*)
202 int ExistingPageProvider::GetCostIndex()
207 } } // end of namespace sd::sidebar
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */