Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sd / source / ui / sidebar / MasterPageContainerProviders.cxx
blob8e1e9163fedde062fdf9993216a0806cf19ece41
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 <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 () (
45 int nWidth,
46 SdPage* pPage,
47 ::sd::PreviewRenderer& rRenderer)
49 Image aPreview;
51 if (pPage != nullptr)
53 // Use the given renderer to create a preview of the given page
54 // object.
55 aPreview = rRenderer.RenderPage(
56 pPage,
57 nWidth);
60 return aPreview;
63 int PagePreviewProvider::GetCostIndex()
65 return 5;
68 bool PagePreviewProvider::NeedsPageObject()
70 return true;
73 //===== TemplatePreviewProvider ===============================================
75 TemplatePreviewProvider::TemplatePreviewProvider (const OUString& rsURL)
76 : msURL(rsURL)
80 Image TemplatePreviewProvider::operator() (
81 int,
82 SdPage*,
83 ::sd::PreviewRenderer&)
85 return Image(ThumbnailView::readThumbnail(msURL));
88 int TemplatePreviewProvider::GetCostIndex()
90 return 10;
93 bool TemplatePreviewProvider::NeedsPageObject()
95 return false;
98 //===== TemplatePageObjectProvider =============================================
100 TemplatePageObjectProvider::TemplatePageObjectProvider (const OUString& rsURL)
101 : msURL(rsURL),
102 mxDocumentShell()
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");
133 pPage = nullptr;
136 return pPage;
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()
155 return 20;
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()
184 return 15;
187 //===== ExistingPageProvider ==================================================
189 ExistingPageProvider::ExistingPageProvider (SdPage* pPage)
190 : mpPage(pPage)
194 SdPage* ExistingPageProvider::operator() (SdDrawDocument*)
196 return mpPage;
199 int ExistingPageProvider::GetCostIndex()
201 return 0;
204 } } // end of namespace sd::sidebar
206 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */