bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / sidebar / MasterPageContainerProviders.cxx
blobc766054251fc842aee57551ef3543fad3a0a51a0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <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 <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 () (
48 int nWidth,
49 SdPage* pPage,
50 ::sd::PreviewRenderer& rRenderer)
52 Image aPreview;
54 if (pPage != nullptr)
56 // Use the given renderer to create a preview of the given page
57 // object.
58 aPreview = rRenderer.RenderPage(
59 pPage,
60 nWidth);
63 return aPreview;
66 int PagePreviewProvider::GetCostIndex()
68 return 5;
71 bool PagePreviewProvider::NeedsPageObject()
73 return true;
76 //===== TemplatePreviewProvider ===============================================
78 TemplatePreviewProvider::TemplatePreviewProvider (const OUString& rsURL)
79 : msURL(rsURL)
83 Image TemplatePreviewProvider::operator() (
84 int,
85 SdPage*,
86 ::sd::PreviewRenderer&)
88 return Image(ThumbnailView::readThumbnail(msURL));
91 int TemplatePreviewProvider::GetCostIndex()
93 return 10;
96 bool TemplatePreviewProvider::NeedsPageObject()
98 return false;
101 //===== TemplatePageObjectProvider =============================================
103 TemplatePageObjectProvider::TemplatePageObjectProvider (const OUString& rsURL)
104 : msURL(rsURL),
105 mxDocumentShell()
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");
136 pPage = nullptr;
139 return pPage;
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()
158 return 20;
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()
187 return 15;
190 //===== ExistingPageProvider ==================================================
192 ExistingPageProvider::ExistingPageProvider (SdPage* pPage)
193 : mpPage(pPage)
197 SdPage* ExistingPageProvider::operator() (SdDrawDocument*)
199 return mpPage;
202 int ExistingPageProvider::GetCostIndex()
204 return 0;
207 } } // end of namespace sd::sidebar
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */