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 <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 () (
50 ::sd::PreviewRenderer
& rRenderer
)
56 // Use the given renderer to create a preview of the given page
58 aPreview
= rRenderer
.RenderPage(
68 int PagePreviewProvider::GetCostIndex()
73 bool PagePreviewProvider::NeedsPageObject()
78 //===== TemplatePreviewProvider ===============================================
80 TemplatePreviewProvider::TemplatePreviewProvider (const OUString
& rsURL
)
85 Image
TemplatePreviewProvider::operator() (
88 ::sd::PreviewRenderer
& rRenderer
)
95 return Image(ThumbnailView::readThumbnail(msURL
));
98 int TemplatePreviewProvider::GetCostIndex()
103 bool TemplatePreviewProvider::NeedsPageObject()
108 //===== TemplatePageObjectProvider =============================================
110 TemplatePageObjectProvider::TemplatePageObjectProvider (const OUString
& rsURL
)
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".
139 pPage
->SetPrecious(false);
143 catch (const uno::RuntimeException
&)
145 DBG_UNHANDLED_EXCEPTION();
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()
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
);
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()
211 bool DefaultPageObjectProvider::operator== (const PageObjectProvider
& rProvider
)
213 return (dynamic_cast<const DefaultPageObjectProvider
*>(&rProvider
) != NULL
);
216 //===== ExistingPageProvider ==================================================
218 ExistingPageProvider::ExistingPageProvider (SdPage
* pPage
)
223 SdPage
* ExistingPageProvider::operator() (SdDrawDocument
* pDocument
)
225 (void)pDocument
; // Unused parameter.
230 int ExistingPageProvider::GetCostIndex()
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
);
245 } } // end of namespace sd::sidebar
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */