bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / sidebar / MasterPageContainerProviders.cxx
blob6474735da5e82e70bcdf6f9854881ea9c5c7808d
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 <comphelper/processfactory.hxx>
26 #include <sfx2/app.hxx>
27 #include <sfx2/sfxsids.hrc>
28 #include <sfx2/thumbnailview.hxx>
29 #include <unotools/ucbstreamhelper.hxx>
30 #include <vcl/image.hxx>
31 #include <vcl/pngread.hxx>
32 #include <com/sun/star/embed/ElementModes.hpp>
33 #include <com/sun/star/embed/StorageFactory.hpp>
34 #include <tools/diagnose_ex.h>
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 != NULL)
56 // Use the given renderer to create a preview of the given page
57 // object.
58 aPreview = rRenderer.RenderPage(
59 pPage,
60 nWidth,
61 OUString(),
62 false);
65 return aPreview;
68 int PagePreviewProvider::GetCostIndex()
70 return 5;
73 bool PagePreviewProvider::NeedsPageObject()
75 return true;
78 //===== TemplatePreviewProvider ===============================================
80 TemplatePreviewProvider::TemplatePreviewProvider (const OUString& rsURL)
81 : msURL(rsURL)
85 Image TemplatePreviewProvider::operator() (
86 int nWidth,
87 SdPage* pPage,
88 ::sd::PreviewRenderer& rRenderer)
90 // Unused parameters.
91 (void)nWidth;
92 (void)pPage;
93 (void)rRenderer;
95 return Image(ThumbnailView::readThumbnail(msURL));
98 int TemplatePreviewProvider::GetCostIndex()
100 return 10;
103 bool TemplatePreviewProvider::NeedsPageObject()
105 return false;
108 //===== TemplatePageObjectProvider =============================================
110 TemplatePageObjectProvider::TemplatePageObjectProvider (const OUString& rsURL)
111 : msURL(rsURL),
112 mxDocumentShell()
116 SdPage* TemplatePageObjectProvider::operator() (SdDrawDocument* pContainerDocument)
118 // Unused parameters.
119 (void)pContainerDocument;
121 SdPage* pPage = NULL;
123 mxDocumentShell = NULL;
124 ::sd::DrawDocShell* pDocumentShell = NULL;
127 // Load the template document and return its first page.
128 pDocumentShell = LoadDocument (msURL);
129 if (pDocumentShell != NULL)
131 SdDrawDocument* pDocument = pDocumentShell->GetDoc();
132 if (pDocument != NULL)
134 pPage = pDocument->GetMasterSdPage(0, PK_STANDARD);
135 // In order to make the newly loaded master page deletable
136 // when copied into documents it is marked as no "precious".
137 // When it is modified then it is marked as "precious".
138 if (pPage != NULL)
139 pPage->SetPrecious(false);
143 catch (const uno::RuntimeException&)
145 DBG_UNHANDLED_EXCEPTION();
146 pPage = NULL;
149 return pPage;
152 ::sd::DrawDocShell* TemplatePageObjectProvider::LoadDocument (const OUString& sFileName)
154 SfxApplication* pSfxApp = SfxGetpApp();
155 SfxItemSet* pSet = new SfxAllItemSet (pSfxApp->GetPool());
156 pSet->Put (SfxBoolItem (SID_TEMPLATE, true));
157 pSet->Put (SfxBoolItem (SID_PREVIEW, true));
158 if (pSfxApp->LoadTemplate (mxDocumentShell, sFileName, true, pSet))
160 mxDocumentShell = NULL;
162 SfxObjectShell* pShell = mxDocumentShell;
163 return PTR_CAST(::sd::DrawDocShell,pShell);
166 int TemplatePageObjectProvider::GetCostIndex()
168 return 20;
171 bool TemplatePageObjectProvider::operator== (const PageObjectProvider& rProvider)
173 const TemplatePageObjectProvider* pTemplatePageObjectProvider
174 = dynamic_cast<const TemplatePageObjectProvider*>(&rProvider);
175 if (pTemplatePageObjectProvider != NULL)
176 return (msURL == pTemplatePageObjectProvider->msURL);
177 else
178 return false;
181 //===== DefaultPageObjectProvider ==============================================
183 DefaultPageObjectProvider::DefaultPageObjectProvider()
187 SdPage* DefaultPageObjectProvider::operator () (SdDrawDocument* pContainerDocument)
189 SdPage* pLocalMasterPage = NULL;
190 if (pContainerDocument != NULL)
192 sal_Int32 nIndex (0);
193 SdPage* pLocalSlide = pContainerDocument->GetSdPage((sal_uInt16)nIndex, PK_STANDARD);
194 if (pLocalSlide!=NULL && pLocalSlide->TRG_HasMasterPage())
195 pLocalMasterPage = dynamic_cast<SdPage*>(&pLocalSlide->TRG_GetMasterPage());
198 if (pLocalMasterPage == NULL)
200 DBG_ASSERT(false, "can not create master page for slide");
203 return pLocalMasterPage;
206 int DefaultPageObjectProvider::GetCostIndex()
208 return 15;
211 bool DefaultPageObjectProvider::operator== (const PageObjectProvider& rProvider)
213 return (dynamic_cast<const DefaultPageObjectProvider*>(&rProvider) != NULL);
216 //===== ExistingPageProvider ==================================================
218 ExistingPageProvider::ExistingPageProvider (SdPage* pPage)
219 : mpPage(pPage)
223 SdPage* ExistingPageProvider::operator() (SdDrawDocument* pDocument)
225 (void)pDocument; // Unused parameter.
227 return mpPage;
230 int ExistingPageProvider::GetCostIndex()
232 return 0;
235 bool ExistingPageProvider::operator== (const PageObjectProvider& rProvider)
237 const ExistingPageProvider* pExistingPageProvider
238 = dynamic_cast<const ExistingPageProvider*>(&rProvider);
239 if (pExistingPageProvider != NULL)
240 return (mpPage == pExistingPageProvider->mpPage);
241 else
242 return false;
245 } } // end of namespace sd::sidebar
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */