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>
24 #include <PreviewRenderer.hxx>
25 #include <sfx2/app.hxx>
26 #include <sfx2/sfxsids.hrc>
27 #include <sfx2/thumbnailview.hxx>
28 #include <vcl/image.hxx>
29 #include <com/sun/star/embed/ElementModes.hpp>
30 #include <com/sun/star/embed/StorageFactory.hpp>
31 #include <tools/diagnose_ex.h>
33 using namespace ::com::sun::star
;
34 using namespace ::com::sun::star::uno
;
36 namespace sd
{ namespace sidebar
{
38 //===== PagePreviewProvider ===================================================
40 PagePreviewProvider::PagePreviewProvider()
44 Image
PagePreviewProvider::operator () (
47 ::sd::PreviewRenderer
& rRenderer
)
53 // Use the given renderer to create a preview of the given page
55 aPreview
= rRenderer
.RenderPage(
63 int PagePreviewProvider::GetCostIndex()
68 bool PagePreviewProvider::NeedsPageObject()
73 //===== TemplatePreviewProvider ===============================================
75 TemplatePreviewProvider::TemplatePreviewProvider (const OUString
& rsURL
)
80 Image
TemplatePreviewProvider::operator() (
83 ::sd::PreviewRenderer
&)
85 return Image(ThumbnailView::readThumbnail(msURL
));
88 int TemplatePreviewProvider::GetCostIndex()
93 bool TemplatePreviewProvider::NeedsPageObject()
98 //===== TemplatePageObjectProvider =============================================
100 TemplatePageObjectProvider::TemplatePageObjectProvider (const OUString
& rsURL
)
106 SdPage
* TemplatePageObjectProvider::operator() (SdDrawDocument
*)
108 SdPage
* pPage
= nullptr;
110 mxDocumentShell
= nullptr;
111 ::sd::DrawDocShell
* pDocumentShell
= nullptr;
114 // Load the template document and return its first page.
115 pDocumentShell
= LoadDocument (msURL
);
116 if (pDocumentShell
!= nullptr)
118 SdDrawDocument
* pDocument
= pDocumentShell
->GetDoc();
119 if (pDocument
!= nullptr)
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);
130 catch (const uno::RuntimeException
&)
132 DBG_UNHANDLED_EXCEPTION("sd");
139 ::sd::DrawDocShell
* TemplatePageObjectProvider::LoadDocument (const OUString
& sFileName
)
141 SfxApplication
* pSfxApp
= SfxGetpApp();
142 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
, pSet
))
147 mxDocumentShell
= nullptr;
149 SfxObjectShell
* pShell
= mxDocumentShell
;
150 return dynamic_cast< ::sd::DrawDocShell
*>( pShell
);
153 int TemplatePageObjectProvider::GetCostIndex()
158 //===== DefaultPageObjectProvider ==============================================
160 DefaultPageObjectProvider::DefaultPageObjectProvider()
164 SdPage
* DefaultPageObjectProvider::operator () (SdDrawDocument
* pContainerDocument
)
166 SdPage
* pLocalMasterPage
= nullptr;
167 if (pContainerDocument
!= nullptr)
169 SdPage
* pLocalSlide
= pContainerDocument
->GetSdPage(0, PageKind::Standard
);
170 if (pLocalSlide
!=nullptr && pLocalSlide
->TRG_HasMasterPage())
171 pLocalMasterPage
= dynamic_cast<SdPage
*>(&pLocalSlide
->TRG_GetMasterPage());
174 if (pLocalMasterPage
== nullptr)
176 SAL_WARN( "sd", "can not create master page for slide");
179 return pLocalMasterPage
;
182 int DefaultPageObjectProvider::GetCostIndex()
187 //===== ExistingPageProvider ==================================================
189 ExistingPageProvider::ExistingPageProvider (SdPage
* pPage
)
194 SdPage
* ExistingPageProvider::operator() (SdDrawDocument
*)
199 int ExistingPageProvider::GetCostIndex()
204 } } // end of namespace sd::sidebar
206 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */