Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "MasterPageContainerProviders.hxx"
31 : :
32 : : #include "DrawDocShell.hxx"
33 : : #include "drawdoc.hxx"
34 : : #include "PreviewRenderer.hxx"
35 : : #include <comphelper/processfactory.hxx>
36 : : #include <sfx2/app.hxx>
37 : : #include <sfx2/sfxsids.hrc>
38 : : #include <unotools/ucbstreamhelper.hxx>
39 : : #include <vcl/image.hxx>
40 : : #include <vcl/pngread.hxx>
41 : : #include <com/sun/star/embed/ElementModes.hpp>
42 : : #include <tools/diagnose_ex.h>
43 : :
44 : : using namespace ::com::sun::star;
45 : : using namespace ::com::sun::star::uno;
46 : : using namespace ::sd::toolpanel::controls;
47 : :
48 : :
49 : : namespace sd { namespace toolpanel { namespace controls {
50 : :
51 : :
52 : : //===== PagePreviewProvider ===================================================
53 : :
54 : 0 : PagePreviewProvider::PagePreviewProvider (void)
55 : : {
56 : 0 : }
57 : :
58 : :
59 : :
60 : :
61 : 0 : Image PagePreviewProvider::operator () (
62 : : int nWidth,
63 : : SdPage* pPage,
64 : : ::sd::PreviewRenderer& rRenderer)
65 : : {
66 : 0 : Image aPreview;
67 : :
68 [ # # ]: 0 : if (pPage != NULL)
69 : : {
70 : : // Use the given renderer to create a preview of the given page
71 : : // object.
72 : : aPreview = rRenderer.RenderPage(
73 : : pPage,
74 : : nWidth,
75 : : rtl::OUString(),
76 [ # # ][ # # ]: 0 : false);
[ # # ][ # # ]
[ # # ]
77 : : }
78 : :
79 : 0 : return aPreview;
80 : : }
81 : :
82 : :
83 : :
84 : :
85 : 0 : int PagePreviewProvider::GetCostIndex (void)
86 : : {
87 : 0 : return 5;
88 : : }
89 : :
90 : :
91 : :
92 : :
93 : 0 : bool PagePreviewProvider::NeedsPageObject (void)
94 : : {
95 : 0 : return true;
96 : : }
97 : :
98 : :
99 : :
100 : :
101 : : //===== TemplatePreviewProvider ===============================================
102 : :
103 : 0 : TemplatePreviewProvider::TemplatePreviewProvider (const ::rtl::OUString& rsURL)
104 : 0 : : msURL(rsURL)
105 : : {
106 : 0 : }
107 : :
108 : :
109 : :
110 : :
111 : 0 : Image TemplatePreviewProvider::operator() (
112 : : int nWidth,
113 : : SdPage* pPage,
114 : : ::sd::PreviewRenderer& rRenderer)
115 : : {
116 : : // Unused parameters.
117 : : (void)nWidth;
118 : : (void)pPage;
119 : : (void)rRenderer;
120 : :
121 : : // Load the thumbnail from a template document.
122 : 0 : uno::Reference<io::XInputStream> xIStream;
123 : :
124 : : uno::Reference< lang::XMultiServiceFactory > xServiceManager (
125 [ # # ]: 0 : ::comphelper::getProcessServiceFactory());
126 [ # # ]: 0 : if (xServiceManager.is())
127 : : {
128 : : try
129 : : {
130 : : uno::Reference<lang::XSingleServiceFactory> xStorageFactory(
131 [ # # ]: 0 : xServiceManager->createInstance( "com.sun.star.embed.StorageFactory"),
132 [ # # ][ # # ]: 0 : uno::UNO_QUERY);
133 : :
134 [ # # ]: 0 : if (xStorageFactory.is())
135 : : {
136 [ # # ]: 0 : uno::Sequence<uno::Any> aArgs (2);
137 [ # # ][ # # ]: 0 : aArgs[0] <<= msURL;
138 [ # # ][ # # ]: 0 : aArgs[1] <<= embed::ElementModes::READ;
139 : : uno::Reference<embed::XStorage> xDocStorage (
140 [ # # ]: 0 : xStorageFactory->createInstanceWithArguments(aArgs),
141 [ # # ][ # # ]: 0 : uno::UNO_QUERY);
142 : :
143 : : try
144 : : {
145 [ # # ]: 0 : if (xDocStorage.is())
146 : : {
147 : : uno::Reference<embed::XStorage> xStorage (
148 [ # # ]: 0 : xDocStorage->openStorageElement(
149 : : "Thumbnails",
150 [ # # ]: 0 : embed::ElementModes::READ));
151 [ # # ]: 0 : if (xStorage.is())
152 : : {
153 : : uno::Reference<io::XStream> xThumbnailCopy (
154 [ # # ][ # # ]: 0 : xStorage->cloneStreamElement("thumbnail.png"));
155 [ # # ]: 0 : if (xThumbnailCopy.is())
156 [ # # ][ # # ]: 0 : xIStream = xThumbnailCopy->getInputStream();
[ # # ]
157 [ # # ]: 0 : }
158 : : }
159 : : }
160 [ # # ]: 0 : catch (const uno::Exception& rException)
161 : : {
162 : : OSL_TRACE (
163 : : "caught exception while trying to access Thumbnail/thumbnail.png of %s: %s",
164 : : ::rtl::OUStringToOString(msURL,
165 : : RTL_TEXTENCODING_UTF8).getStr(),
166 : : ::rtl::OUStringToOString(rException.Message,
167 : : RTL_TEXTENCODING_UTF8).getStr());
168 : : }
169 : :
170 : : try
171 : : {
172 : : // An (older) implementation had a bug - The storage
173 : : // name was "Thumbnail" instead of "Thumbnails". The
174 : : // old name is still used as fallback but this code can
175 : : // be removed soon.
176 [ # # ]: 0 : if ( ! xIStream.is())
177 : : {
178 : : uno::Reference<embed::XStorage> xStorage (
179 [ # # ]: 0 : xDocStorage->openStorageElement( "Thumbnail",
180 [ # # ]: 0 : embed::ElementModes::READ));
181 [ # # ]: 0 : if (xStorage.is())
182 : : {
183 : : uno::Reference<io::XStream> xThumbnailCopy (
184 [ # # ][ # # ]: 0 : xStorage->cloneStreamElement("thumbnail.png"));
185 [ # # ]: 0 : if (xThumbnailCopy.is())
186 [ # # ][ # # ]: 0 : xIStream = xThumbnailCopy->getInputStream();
[ # # ]
187 [ # # ]: 0 : }
188 : : }
189 : : }
190 [ # # ]: 0 : catch (const uno::Exception& rException)
191 : : {
192 : : OSL_TRACE (
193 : : "caught exception while trying to access Thumbnails/thumbnail.png of %s: %s",
194 : : ::rtl::OUStringToOString(msURL,
195 : : RTL_TEXTENCODING_UTF8).getStr(),
196 : : ::rtl::OUStringToOString(rException.Message,
197 : : RTL_TEXTENCODING_UTF8).getStr());
198 [ # # ]: 0 : }
199 [ # # ]: 0 : }
200 : : }
201 [ # # ]: 0 : catch (const uno::Exception& rException)
202 : : {
203 : : OSL_TRACE (
204 : : "caught exception while trying to access tuhmbnail of %s: %s",
205 : : ::rtl::OUStringToOString(msURL,
206 : : RTL_TEXTENCODING_UTF8).getStr(),
207 : : ::rtl::OUStringToOString(rException.Message,
208 : : RTL_TEXTENCODING_UTF8).getStr());
209 : : }
210 : : }
211 : :
212 : : // Extract the image from the stream.
213 [ # # ]: 0 : BitmapEx aThumbnail;
214 [ # # ]: 0 : if (xIStream.is())
215 : : {
216 : : ::std::auto_ptr<SvStream> pStream (
217 [ # # ]: 0 : ::utl::UcbStreamHelper::CreateStream (xIStream));
218 [ # # ]: 0 : ::vcl::PNGReader aReader (*pStream);
219 [ # # ][ # # ]: 0 : aThumbnail = aReader.Read ();
[ # # ][ # # ]
[ # # ]
220 : : }
221 : :
222 : : // Note that the preview is returned without scaling it to the desired
223 : : // width. This gives the caller the chance to take advantage of a
224 : : // possibly larger resolution then was asked for.
225 [ # # ][ # # ]: 0 : return aThumbnail;
226 : : }
227 : :
228 : :
229 : :
230 : :
231 : 0 : int TemplatePreviewProvider::GetCostIndex (void)
232 : : {
233 : 0 : return 10;
234 : : }
235 : :
236 : :
237 : :
238 : :
239 : 0 : bool TemplatePreviewProvider::NeedsPageObject (void)
240 : : {
241 : 0 : return false;
242 : : }
243 : :
244 : :
245 : :
246 : :
247 : : //===== TemplatePageObjectProvider =============================================
248 : :
249 : 0 : TemplatePageObjectProvider::TemplatePageObjectProvider (const ::rtl::OUString& rsURL)
250 : : : msURL(rsURL),
251 : 0 : mxDocumentShell()
252 : : {
253 : 0 : }
254 : :
255 : :
256 : :
257 : :
258 : 0 : SdPage* TemplatePageObjectProvider::operator() (SdDrawDocument* pContainerDocument)
259 : : {
260 : : // Unused parameters.
261 : : (void)pContainerDocument;
262 : :
263 : 0 : SdPage* pPage = NULL;
264 : :
265 : 0 : mxDocumentShell = NULL;
266 : 0 : ::sd::DrawDocShell* pDocumentShell = NULL;
267 : : try
268 : : {
269 : : // Load the template document and return its first page.
270 [ # # ]: 0 : pDocumentShell = LoadDocument (msURL);
271 [ # # ]: 0 : if (pDocumentShell != NULL)
272 : : {
273 [ # # ]: 0 : SdDrawDocument* pDocument = pDocumentShell->GetDoc();
274 [ # # ]: 0 : if (pDocument != NULL)
275 : : {
276 [ # # ]: 0 : pPage = pDocument->GetMasterSdPage(0, PK_STANDARD);
277 : : // In order to make the newly loaded master page deletable
278 : : // when copied into documents it is marked as no "precious".
279 : : // When it is modified then it is marked as "precious".
280 [ # # ]: 0 : if (pPage != NULL)
281 [ # # ]: 0 : pPage->SetPrecious(false);
282 : : }
283 : : }
284 : : }
285 : 0 : catch (const uno::RuntimeException&)
286 : : {
287 : : DBG_UNHANDLED_EXCEPTION();
288 : 0 : pPage = NULL;
289 : : }
290 : :
291 [ # # ]: 0 : return pPage;
292 : : }
293 : :
294 : :
295 : :
296 : :
297 : 0 : ::sd::DrawDocShell* TemplatePageObjectProvider::LoadDocument (const ::rtl::OUString& sFileName)
298 : : {
299 : 0 : SfxApplication* pSfxApp = SFX_APP();
300 [ # # ]: 0 : SfxItemSet* pSet = new SfxAllItemSet (pSfxApp->GetPool());
301 [ # # ]: 0 : pSet->Put (SfxBoolItem (SID_TEMPLATE, sal_True));
302 [ # # ]: 0 : pSet->Put (SfxBoolItem (SID_PREVIEW, sal_True));
303 [ # # ][ # # ]: 0 : if (pSfxApp->LoadTemplate (mxDocumentShell, sFileName, sal_True, pSet))
304 : : {
305 : 0 : mxDocumentShell = NULL;
306 : : }
307 : 0 : SfxObjectShell* pShell = mxDocumentShell;
308 [ # # ][ # # ]: 0 : return PTR_CAST(::sd::DrawDocShell,pShell);
309 : : }
310 : :
311 : :
312 : :
313 : :
314 : 0 : int TemplatePageObjectProvider::GetCostIndex (void)
315 : : {
316 : 0 : return 20;
317 : : }
318 : :
319 : :
320 : :
321 : :
322 : 0 : bool TemplatePageObjectProvider::operator== (const PageObjectProvider& rProvider)
323 : : {
324 : : const TemplatePageObjectProvider* pTemplatePageObjectProvider
325 [ # # ]: 0 : = dynamic_cast<const TemplatePageObjectProvider*>(&rProvider);
326 [ # # ]: 0 : if (pTemplatePageObjectProvider != NULL)
327 : 0 : return (msURL == pTemplatePageObjectProvider->msURL);
328 : : else
329 : 0 : return false;
330 : : }
331 : :
332 : :
333 : :
334 : :
335 : : //===== DefaultPageObjectProvider ==============================================
336 : :
337 : 0 : DefaultPageObjectProvider::DefaultPageObjectProvider (void)
338 : : {
339 : 0 : }
340 : :
341 : :
342 : :
343 : :
344 : 0 : SdPage* DefaultPageObjectProvider::operator () (SdDrawDocument* pContainerDocument)
345 : : {
346 : 0 : SdPage* pLocalMasterPage = NULL;
347 [ # # ]: 0 : if (pContainerDocument != NULL)
348 : : {
349 : 0 : sal_Int32 nIndex (0);
350 : 0 : SdPage* pLocalSlide = pContainerDocument->GetSdPage((sal_uInt16)nIndex, PK_STANDARD);
351 [ # # ][ # # ]: 0 : if (pLocalSlide!=NULL && pLocalSlide->TRG_HasMasterPage())
[ # # ]
352 [ # # ]: 0 : pLocalMasterPage = dynamic_cast<SdPage*>(&pLocalSlide->TRG_GetMasterPage());
353 : : }
354 : :
355 : : if (pLocalMasterPage == NULL)
356 : : {
357 : : DBG_ASSERT(false, "can not create master page for slide");
358 : : }
359 : :
360 : 0 : return pLocalMasterPage;
361 : : }
362 : :
363 : :
364 : :
365 : :
366 : 0 : int DefaultPageObjectProvider::GetCostIndex (void)
367 : : {
368 : 0 : return 15;
369 : : }
370 : :
371 : :
372 : :
373 : :
374 : 0 : bool DefaultPageObjectProvider::operator== (const PageObjectProvider& rProvider)
375 : : {
376 [ # # ][ # # ]: 0 : return (dynamic_cast<const DefaultPageObjectProvider*>(&rProvider) != NULL);
377 : : }
378 : :
379 : :
380 : :
381 : :
382 : : //===== ExistingPageProvider ==================================================
383 : :
384 : 0 : ExistingPageProvider::ExistingPageProvider (SdPage* pPage)
385 : 0 : : mpPage(pPage)
386 : : {
387 : 0 : }
388 : :
389 : :
390 : :
391 : :
392 : 0 : SdPage* ExistingPageProvider::operator() (SdDrawDocument* pDocument)
393 : : {
394 : : (void)pDocument; // Unused parameter.
395 : :
396 : 0 : return mpPage;
397 : : }
398 : :
399 : :
400 : :
401 : :
402 : 0 : int ExistingPageProvider::GetCostIndex (void)
403 : : {
404 : 0 : return 0;
405 : : }
406 : :
407 : :
408 : :
409 : :
410 : 0 : bool ExistingPageProvider::operator== (const PageObjectProvider& rProvider)
411 : : {
412 : : const ExistingPageProvider* pExistingPageProvider
413 [ # # ]: 0 : = dynamic_cast<const ExistingPageProvider*>(&rProvider);
414 [ # # ]: 0 : if (pExistingPageProvider != NULL)
415 : 0 : return (mpPage == pExistingPageProvider->mpPage);
416 : : else
417 : 0 : return false;
418 : : }
419 : :
420 : :
421 : : } } } // end of namespace ::sd::toolpanel::controls
422 : :
423 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|