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 "MasterPageContainer.hxx"
31 : :
32 : : #include "MasterPageDescriptor.hxx"
33 : : #include "MasterPageContainerFiller.hxx"
34 : : #include "MasterPageContainerQueue.hxx"
35 : : #include "TemplateScanner.hxx"
36 : : #include "tools/AsynchronousTask.hxx"
37 : : #include "strings.hrc"
38 : : #include <algorithm>
39 : : #include <list>
40 : : #include <set>
41 : :
42 : : #include "unomodel.hxx"
43 : : #include <com/sun/star/frame/XComponentLoader.hpp>
44 : : #include <com/sun/star/io/XStream.hpp>
45 : : #include <com/sun/star/io/XInputStream.hpp>
46 : : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
47 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
48 : : #include <com/sun/star/uno/Reference.hxx>
49 : : #include <com/sun/star/uno/Any.hxx>
50 : : #include <com/sun/star/uno/Sequence.hxx>
51 : : #include <com/sun/star/util/XCloseable.hpp>
52 : : #include <comphelper/processfactory.hxx>
53 : : #include <sfx2/app.hxx>
54 : : #include <svx/svdpage.hxx>
55 : : #include "DrawDocShell.hxx"
56 : : #include "drawdoc.hxx"
57 : : #include "sdpage.hxx"
58 : : #include <svl/itemset.hxx>
59 : : #include <svl/eitem.hxx>
60 : : #include "sdresid.hxx"
61 : : #include "tools/TimerBasedTaskExecution.hxx"
62 : : #include "pres.hxx"
63 : : #include <osl/mutex.hxx>
64 : : #include <boost/weak_ptr.hpp>
65 : :
66 : : using namespace ::com::sun::star;
67 : : using namespace ::com::sun::star::uno;
68 : : using namespace ::sd::toolpanel::controls;
69 : :
70 : : namespace {
71 : :
72 : : typedef ::std::vector<SharedMasterPageDescriptor> MasterPageContainerType;
73 : :
74 : : } // end of anonymous namespace
75 : :
76 : :
77 : : namespace sd { namespace toolpanel { namespace controls {
78 : :
79 : :
80 : : /** Inner implementation class of the MasterPageContainer.
81 : : */
82 : : class MasterPageContainer::Implementation
83 : : : public SdGlobalResource,
84 : : public MasterPageContainerFiller::ContainerAdapter,
85 : : public MasterPageContainerQueue::ContainerAdapter
86 : : {
87 : : public:
88 : : mutable ::osl::Mutex maMutex;
89 : :
90 : : static ::boost::weak_ptr<Implementation> mpInstance;
91 : : MasterPageContainerType maContainer;
92 : :
93 : : static ::boost::shared_ptr<Implementation> Instance (void);
94 : :
95 : : void LateInit (void);
96 : : void AddChangeListener (const Link& rLink);
97 : : void RemoveChangeListener (const Link& rLink);
98 : : void UpdatePreviewSizePixel (void);
99 : : Size GetPreviewSizePixel (PreviewSize eSize) const;
100 : :
101 : : bool HasToken (Token aToken) const;
102 : : const SharedMasterPageDescriptor GetDescriptor (MasterPageContainer::Token aToken) const;
103 : : SharedMasterPageDescriptor GetDescriptor (MasterPageContainer::Token aToken);
104 : : virtual Token PutMasterPage (const SharedMasterPageDescriptor& rDescriptor);
105 : : void InvalidatePreview (Token aToken);
106 : : Image GetPreviewForToken (
107 : : Token aToken,
108 : : PreviewSize ePreviewSize);
109 : : PreviewState GetPreviewState (Token aToken) const;
110 : : bool RequestPreview (Token aToken);
111 : :
112 : : Reference<frame::XModel> GetModel (void);
113 : : SdDrawDocument* GetDocument (void);
114 : :
115 : : void FireContainerChange (
116 : : MasterPageContainerChangeEvent::EventType eType,
117 : : Token aToken,
118 : : bool bNotifyAsynchronously = false);
119 : :
120 : : virtual bool UpdateDescriptor (
121 : : const SharedMasterPageDescriptor& rpDescriptor,
122 : : bool bForcePageObject,
123 : : bool bForcePreview,
124 : : bool bSendEvents);
125 : :
126 : : void ReleaseDescriptor (Token aToken);
127 : :
128 : : /** Called by the MasterPageContainerFiller to notify that all master
129 : : pages from template documents have been added.
130 : : */
131 : : virtual void FillingDone (void);
132 : :
133 : : private:
134 : : Implementation (void);
135 : : virtual ~Implementation (void);
136 : :
137 : : class Deleter { public:
138 [ # # ]: 0 : void operator() (Implementation* pObject) { delete pObject; }
139 : : };
140 : : friend class Deleter;
141 : :
142 : : enum InitializationState { NOT_INITIALIZED, INITIALIZING, INITIALIZED } meInitializationState;
143 : :
144 : : ::boost::scoped_ptr<MasterPageContainerQueue> mpRequestQueue;
145 : : ::com::sun::star::uno::Reference<com::sun::star::frame::XModel> mxModel;
146 : : SdDrawDocument* mpDocument;
147 : : PreviewRenderer maPreviewRenderer;
148 : : /** Remember whether the first page object has already been used to
149 : : determine the correct size ratio.
150 : : */
151 : : bool mbFirstPageObjectSeen;
152 : :
153 : : // The widths for the previews contain two pixels for the border that is
154 : : // painted arround the preview.
155 : : static const int SMALL_PREVIEW_WIDTH = 72 + 2;
156 : : static const int LARGE_PREVIEW_WIDTH = 2*72 + 2;
157 : :
158 : : /** This substition of page preview shows "Preparing preview" and is
159 : : shown as long as the actual previews are not being present.
160 : : */
161 : : Image maLargePreviewBeingCreated;
162 : : Image maSmallPreviewBeingCreated;
163 : :
164 : : /** This substition of page preview is shown when a preview can not be
165 : : created and thus is not available.
166 : : */
167 : : Image maLargePreviewNotAvailable;
168 : : Image maSmallPreviewNotAvailable;
169 : :
170 : : ::std::vector<Link> maChangeListeners;
171 : :
172 : : // We have to remember the tasks for initialization and filling in case
173 : : // a MasterPageContainer object is destroyed before these tasks have
174 : : // been completed.
175 : : ::boost::weak_ptr<sd::tools::TimerBasedTaskExecution> mpFillerTask;
176 : :
177 : : Size maSmallPreviewSizePixel;
178 : : Size maLargePreviewSizePixel;
179 : : bool mbPageRatioKnown;
180 : :
181 : : bool mbContainerCleaningPending;
182 : :
183 : : typedef ::std::pair<MasterPageContainerChangeEvent::EventType,Token> EventData;
184 : : DECL_LINK(AsynchronousNotifyCallback, EventData*);
185 : : ::sd::DrawDocShell* LoadDocument (
186 : : const String& sFileName,
187 : : SfxObjectShellLock& rxDocumentShell);
188 : :
189 : : Image GetPreviewSubstitution (sal_uInt16 nId, PreviewSize ePreviewSize);
190 : :
191 : : void CleanContainer (void);
192 : : };
193 : :
194 : :
195 : :
196 : :
197 : : //===== MasterPageContainer ===================================================
198 : :
199 : : ::boost::weak_ptr<MasterPageContainer::Implementation>
200 : 25 : MasterPageContainer::Implementation::mpInstance;
201 : : static const MasterPageContainer::Token NIL_TOKEN (-1);
202 : :
203 : :
204 : :
205 : :
206 : : ::boost::shared_ptr<MasterPageContainer::Implementation>
207 : 0 : MasterPageContainer::Implementation::Instance (void)
208 : : {
209 : 0 : ::boost::shared_ptr<MasterPageContainer::Implementation> pInstance;
210 : :
211 [ # # ]: 0 : if (Implementation::mpInstance.expired())
212 : : {
213 : : ::osl::GetGlobalMutex aMutexFunctor;
214 [ # # ][ # # ]: 0 : ::osl::MutexGuard aGuard (aMutexFunctor());
215 [ # # ]: 0 : if (Implementation::mpInstance.expired())
216 : : {
217 : : OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
218 : : pInstance = ::boost::shared_ptr<MasterPageContainer::Implementation>(
219 : 0 : new MasterPageContainer::Implementation(),
220 [ # # ][ # # ]: 0 : MasterPageContainer::Implementation::Deleter());
[ # # ][ # # ]
[ # # ]
221 [ # # ][ # # ]: 0 : SdGlobalResourceContainer::Instance().AddResource(pInstance);
[ # # ][ # # ]
222 [ # # ]: 0 : Implementation::mpInstance = pInstance;
223 : : }
224 : : else
225 : : pInstance = ::boost::shared_ptr<MasterPageContainer::Implementation>(
226 [ # # ][ # # ]: 0 : Implementation::mpInstance);
[ # # ][ # # ]
227 : : }
228 : : else
229 : : {
230 : : OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
231 : : pInstance = ::boost::shared_ptr<MasterPageContainer::Implementation>(
232 [ # # ][ # # ]: 0 : Implementation::mpInstance);
[ # # ]
233 : : }
234 : :
235 : : DBG_ASSERT (pInstance.get()!=NULL,
236 : : "MasterPageContainer::Implementation::Instance(): instance is NULL");
237 : 0 : return pInstance;
238 : : }
239 : :
240 : :
241 : :
242 : :
243 : 0 : MasterPageContainer::MasterPageContainer (void)
244 : : : mpImpl(Implementation::Instance()),
245 : 0 : mePreviewSize(SMALL)
246 : : {
247 [ # # ]: 0 : mpImpl->LateInit();
248 : 0 : }
249 : :
250 : :
251 : :
252 : :
253 : 0 : MasterPageContainer::~MasterPageContainer (void)
254 : : {
255 [ # # ]: 0 : }
256 : :
257 : :
258 : :
259 : :
260 : 0 : void MasterPageContainer::AddChangeListener (const Link& rLink)
261 : : {
262 : 0 : mpImpl->AddChangeListener(rLink);
263 : 0 : }
264 : :
265 : :
266 : :
267 : :
268 : 0 : void MasterPageContainer::RemoveChangeListener (const Link& rLink)
269 : : {
270 : 0 : mpImpl->RemoveChangeListener(rLink);
271 : 0 : }
272 : :
273 : :
274 : :
275 : :
276 : 0 : void MasterPageContainer::SetPreviewSize (PreviewSize eSize)
277 : : {
278 : 0 : mePreviewSize = eSize;
279 : : mpImpl->FireContainerChange(
280 : : MasterPageContainerChangeEvent::SIZE_CHANGED,
281 : 0 : NIL_TOKEN);
282 : 0 : }
283 : :
284 : :
285 : :
286 : :
287 : 0 : MasterPageContainer::PreviewSize MasterPageContainer::GetPreviewSize (void) const
288 : : {
289 : 0 : return mePreviewSize;
290 : : }
291 : :
292 : :
293 : :
294 : :
295 : 0 : Size MasterPageContainer::GetPreviewSizePixel (void) const
296 : : {
297 : 0 : return mpImpl->GetPreviewSizePixel(mePreviewSize);
298 : : }
299 : :
300 : :
301 : :
302 : :
303 : 0 : MasterPageContainer::Token MasterPageContainer::PutMasterPage (
304 : : const SharedMasterPageDescriptor& rDescriptor)
305 : : {
306 : 0 : return mpImpl->PutMasterPage(rDescriptor);
307 : : }
308 : :
309 : :
310 : :
311 : :
312 : 0 : void MasterPageContainer::AcquireToken (Token aToken)
313 : : {
314 [ # # ]: 0 : SharedMasterPageDescriptor pDescriptor = mpImpl->GetDescriptor(aToken);
315 [ # # ]: 0 : if (pDescriptor.get() != NULL)
316 : : {
317 : 0 : ++pDescriptor->mnUseCount;
318 [ # # ]: 0 : }
319 : 0 : }
320 : :
321 : :
322 : :
323 : :
324 : 0 : void MasterPageContainer::ReleaseToken (Token aToken)
325 : : {
326 [ # # ]: 0 : SharedMasterPageDescriptor pDescriptor = mpImpl->GetDescriptor(aToken);
327 [ # # ]: 0 : if (pDescriptor.get() != NULL)
328 : : {
329 : : OSL_ASSERT(pDescriptor->mnUseCount>0);
330 : 0 : --pDescriptor->mnUseCount;
331 [ # # ]: 0 : if (pDescriptor->mnUseCount <= 0)
332 : : {
333 [ # # ]: 0 : switch (pDescriptor->meOrigin)
334 : : {
335 : : case DEFAULT:
336 : : case TEMPLATE:
337 : : default:
338 : 0 : break;
339 : :
340 : : case MASTERPAGE:
341 [ # # ]: 0 : mpImpl->ReleaseDescriptor(aToken);
342 : 0 : break;
343 : : }
344 : : }
345 [ # # ]: 0 : }
346 : 0 : }
347 : :
348 : :
349 : :
350 : :
351 : 0 : int MasterPageContainer::GetTokenCount (void) const
352 : : {
353 [ # # ]: 0 : const ::osl::MutexGuard aGuard (mpImpl->maMutex);
354 : :
355 [ # # ]: 0 : return mpImpl->maContainer.size();
356 : : }
357 : :
358 : :
359 : :
360 : :
361 : 0 : bool MasterPageContainer::HasToken (Token aToken) const
362 : : {
363 [ # # ]: 0 : const ::osl::MutexGuard aGuard (mpImpl->maMutex);
364 : :
365 [ # # ][ # # ]: 0 : return mpImpl->HasToken(aToken);
366 : : }
367 : :
368 : :
369 : :
370 : :
371 : 0 : MasterPageContainer::Token MasterPageContainer::GetTokenForIndex (int nIndex)
372 : : {
373 [ # # ]: 0 : const ::osl::MutexGuard aGuard (mpImpl->maMutex);
374 : :
375 : 0 : Token aResult (NIL_TOKEN);
376 [ # # ][ # # ]: 0 : if (HasToken(nIndex))
377 : 0 : aResult = mpImpl->maContainer[nIndex]->maToken;
378 [ # # ]: 0 : return aResult;
379 : : }
380 : :
381 : :
382 : :
383 : :
384 : 0 : MasterPageContainer::Token MasterPageContainer::GetTokenForURL (
385 : : const String& sURL)
386 : : {
387 [ # # ]: 0 : const ::osl::MutexGuard aGuard (mpImpl->maMutex);
388 : :
389 : 0 : Token aResult (NIL_TOKEN);
390 [ # # ]: 0 : if (sURL.Len() > 0)
391 : : {
392 : : MasterPageContainerType::iterator iEntry (
393 : : ::std::find_if (
394 : 0 : mpImpl->maContainer.begin(),
395 : 0 : mpImpl->maContainer.end(),
396 [ # # ]: 0 : MasterPageDescriptor::URLComparator(sURL)));
[ # # # # ]
397 [ # # ][ # # ]: 0 : if (iEntry != mpImpl->maContainer.end())
398 : 0 : aResult = (*iEntry)->maToken;
399 : : }
400 [ # # ]: 0 : return aResult;
401 : : }
402 : :
403 : :
404 : :
405 : :
406 : 0 : MasterPageContainer::Token MasterPageContainer::GetTokenForStyleName (const String& sStyleName)
407 : : {
408 [ # # ]: 0 : const ::osl::MutexGuard aGuard (mpImpl->maMutex);
409 : :
410 : 0 : Token aResult (NIL_TOKEN);
411 [ # # ]: 0 : if (sStyleName.Len() > 0)
412 : : {
413 : : MasterPageContainerType::iterator iEntry (
414 : : ::std::find_if (
415 : 0 : mpImpl->maContainer.begin(),
416 : 0 : mpImpl->maContainer.end(),
417 [ # # ]: 0 : MasterPageDescriptor::StyleNameComparator(sStyleName)));
[ # # # # ]
418 [ # # ][ # # ]: 0 : if (iEntry != mpImpl->maContainer.end())
419 : 0 : aResult = (*iEntry)->maToken;
420 : : }
421 [ # # ]: 0 : return aResult;
422 : : }
423 : :
424 : :
425 : :
426 : :
427 : 0 : MasterPageContainer::Token MasterPageContainer::GetTokenForPageObject (
428 : : const SdPage* pPage)
429 : : {
430 [ # # ]: 0 : const ::osl::MutexGuard aGuard (mpImpl->maMutex);
431 : :
432 : 0 : Token aResult (NIL_TOKEN);
433 [ # # ]: 0 : if (pPage != NULL)
434 : : {
435 : : MasterPageContainerType::iterator iEntry (
436 : : ::std::find_if (
437 : 0 : mpImpl->maContainer.begin(),
438 : 0 : mpImpl->maContainer.end(),
439 [ # # # # ]: 0 : MasterPageDescriptor::PageObjectComparator(pPage)));
440 [ # # ][ # # ]: 0 : if (iEntry != mpImpl->maContainer.end())
441 : 0 : aResult = (*iEntry)->maToken;
442 : : }
443 [ # # ]: 0 : return aResult;
444 : : }
445 : :
446 : :
447 : :
448 : :
449 : 0 : String MasterPageContainer::GetURLForToken (
450 : : MasterPageContainer::Token aToken)
451 : : {
452 [ # # ]: 0 : const ::osl::MutexGuard aGuard (mpImpl->maMutex);
453 : :
454 [ # # ]: 0 : SharedMasterPageDescriptor pDescriptor = mpImpl->GetDescriptor(aToken);
455 [ # # ]: 0 : if (pDescriptor.get() != NULL)
456 [ # # ]: 0 : return pDescriptor->msURL;
457 : : else
458 [ # # ][ # # ]: 0 : return String();
[ # # ]
459 : : }
460 : :
461 : :
462 : :
463 : :
464 : 0 : String MasterPageContainer::GetPageNameForToken (
465 : : MasterPageContainer::Token aToken)
466 : : {
467 [ # # ]: 0 : const ::osl::MutexGuard aGuard (mpImpl->maMutex);
468 : :
469 [ # # ]: 0 : SharedMasterPageDescriptor pDescriptor = mpImpl->GetDescriptor(aToken);
470 [ # # ]: 0 : if (pDescriptor.get() != NULL)
471 [ # # ]: 0 : return pDescriptor->msPageName;
472 : : else
473 [ # # ][ # # ]: 0 : return String();
[ # # ]
474 : : }
475 : :
476 : :
477 : :
478 : :
479 : 0 : String MasterPageContainer::GetStyleNameForToken (
480 : : MasterPageContainer::Token aToken)
481 : : {
482 [ # # ]: 0 : const ::osl::MutexGuard aGuard (mpImpl->maMutex);
483 : :
484 [ # # ]: 0 : SharedMasterPageDescriptor pDescriptor = mpImpl->GetDescriptor(aToken);
485 [ # # ]: 0 : if (pDescriptor.get() != NULL)
486 [ # # ]: 0 : return pDescriptor->msStyleName;
487 : : else
488 [ # # ][ # # ]: 0 : return String();
[ # # ]
489 : : }
490 : :
491 : :
492 : :
493 : :
494 : 0 : SdPage* MasterPageContainer::GetPageObjectForToken (
495 : : MasterPageContainer::Token aToken,
496 : : bool bLoad)
497 : : {
498 [ # # ]: 0 : const ::osl::MutexGuard aGuard (mpImpl->maMutex);
499 : :
500 : 0 : SdPage* pPageObject = NULL;
501 [ # # ]: 0 : SharedMasterPageDescriptor pDescriptor = mpImpl->GetDescriptor(aToken);
502 [ # # ]: 0 : if (pDescriptor.get() != NULL)
503 : : {
504 : 0 : pPageObject = pDescriptor->mpMasterPage;
505 [ # # ]: 0 : if (pPageObject == NULL)
506 : : {
507 : : // The page object is not (yet) present. Call
508 : : // UpdateDescriptor() to trigger the PageObjectProvider() to
509 : : // provide it.
510 [ # # ]: 0 : if (bLoad)
511 [ # # ]: 0 : mpImpl->GetModel();
512 [ # # ][ # # ]: 0 : if (mpImpl->UpdateDescriptor(pDescriptor,bLoad,false, true))
513 : 0 : pPageObject = pDescriptor->mpMasterPage;
514 : : }
515 : : }
516 [ # # ][ # # ]: 0 : return pPageObject;
517 : : }
518 : :
519 : :
520 : :
521 : :
522 : 0 : MasterPageContainer::Origin MasterPageContainer::GetOriginForToken (Token aToken)
523 : : {
524 [ # # ]: 0 : const ::osl::MutexGuard aGuard (mpImpl->maMutex);
525 : :
526 [ # # ]: 0 : SharedMasterPageDescriptor pDescriptor = mpImpl->GetDescriptor(aToken);
527 [ # # ]: 0 : if (pDescriptor.get() != NULL)
528 : 0 : return pDescriptor->meOrigin;
529 : : else
530 [ # # ][ # # ]: 0 : return UNKNOWN;
531 : : }
532 : :
533 : :
534 : :
535 : :
536 : 0 : sal_Int32 MasterPageContainer::GetTemplateIndexForToken (Token aToken)
537 : : {
538 [ # # ]: 0 : const ::osl::MutexGuard aGuard (mpImpl->maMutex);
539 : :
540 [ # # ]: 0 : SharedMasterPageDescriptor pDescriptor = mpImpl->GetDescriptor(aToken);
541 [ # # ]: 0 : if (pDescriptor.get() != NULL)
542 : 0 : return pDescriptor->mnTemplateIndex;
543 : : else
544 [ # # ][ # # ]: 0 : return -1;
545 : : }
546 : :
547 : :
548 : :
549 : :
550 : 0 : SharedMasterPageDescriptor MasterPageContainer::GetDescriptorForToken (
551 : : MasterPageContainer::Token aToken)
552 : : {
553 [ # # ]: 0 : const ::osl::MutexGuard aGuard (mpImpl->maMutex);
554 : :
555 [ # # ][ # # ]: 0 : return mpImpl->GetDescriptor(aToken);
556 : : }
557 : :
558 : :
559 : :
560 : 0 : void MasterPageContainer::InvalidatePreview (MasterPageContainer::Token aToken)
561 : : {
562 : 0 : mpImpl->InvalidatePreview(aToken);
563 : 0 : }
564 : :
565 : :
566 : :
567 : :
568 : 0 : Image MasterPageContainer::GetPreviewForToken (MasterPageContainer::Token aToken)
569 : : {
570 : 0 : return mpImpl->GetPreviewForToken(aToken,mePreviewSize);
571 : : }
572 : :
573 : :
574 : :
575 : :
576 : 0 : MasterPageContainer::PreviewState MasterPageContainer::GetPreviewState (Token aToken)
577 : : {
578 : 0 : return mpImpl->GetPreviewState(aToken);
579 : : }
580 : :
581 : :
582 : :
583 : :
584 : 0 : bool MasterPageContainer::RequestPreview (Token aToken)
585 : : {
586 : 0 : return mpImpl->RequestPreview(aToken);
587 : : }
588 : :
589 : :
590 : :
591 : :
592 : : //==== Implementation ================================================
593 : :
594 : 0 : MasterPageContainer::Implementation::Implementation (void)
595 : : : maMutex(),
596 : : maContainer(),
597 : : meInitializationState(NOT_INITIALIZED),
598 : : mpRequestQueue(NULL),
599 : : mxModel(NULL),
600 : : mpDocument(NULL),
601 : : maPreviewRenderer(),
602 : : mbFirstPageObjectSeen(false),
603 : : maLargePreviewBeingCreated(),
604 : : maSmallPreviewBeingCreated(),
605 : : maLargePreviewNotAvailable(),
606 : : maSmallPreviewNotAvailable(),
607 : : maChangeListeners(),
608 : : maSmallPreviewSizePixel(),
609 : : maLargePreviewSizePixel(),
610 : : mbPageRatioKnown(false),
611 [ # # ][ # # ]: 0 : mbContainerCleaningPending(true)
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
612 : :
613 : : {
614 [ # # ]: 0 : UpdatePreviewSizePixel();
615 : 0 : }
616 : :
617 : :
618 : :
619 : :
620 [ # # ][ # # ]: 0 : MasterPageContainer::Implementation::~Implementation (void)
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
621 : : {
622 : : // When the initializer or filler tasks are still running then we have
623 : : // to stop them now in order to prevent them from calling us back.
624 [ # # ]: 0 : tools::TimerBasedTaskExecution::ReleaseTask(mpFillerTask);
625 : :
626 [ # # ]: 0 : mpRequestQueue.reset();
627 : :
628 [ # # ]: 0 : uno::Reference<util::XCloseable> xCloseable (mxModel, uno::UNO_QUERY);
629 [ # # ]: 0 : if (xCloseable.is())
630 : : {
631 : : try
632 : : {
633 [ # # ][ # # ]: 0 : xCloseable->close(true);
634 : : }
635 [ # # ]: 0 : catch (const ::com::sun::star::util::CloseVetoException&)
636 : : {
637 : : }
638 : : }
639 [ # # ]: 0 : mxModel = NULL;
640 [ # # ][ # # ]: 0 : }
641 : :
642 : :
643 : :
644 : :
645 : 0 : void MasterPageContainer::Implementation::LateInit (void)
646 : : {
647 [ # # ]: 0 : const ::osl::MutexGuard aGuard (maMutex);
648 : :
649 [ # # ]: 0 : if (meInitializationState == NOT_INITIALIZED)
650 : : {
651 : 0 : meInitializationState = INITIALIZING;
652 : :
653 : : OSL_ASSERT(Instance().get()==this);
654 : : mpRequestQueue.reset(MasterPageContainerQueue::Create(
655 [ # # ][ # # ]: 0 : ::boost::shared_ptr<MasterPageContainerQueue::ContainerAdapter>(Instance())));
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
656 : :
657 : : mpFillerTask = ::sd::tools::TimerBasedTaskExecution::Create(
658 [ # # ]: 0 : ::boost::shared_ptr<tools::AsynchronousTask>(new MasterPageContainerFiller(*this)),
659 : : 5,
660 [ # # ][ # # ]: 0 : 50);
[ # # ][ # # ]
[ # # ][ # # ]
661 : :
662 : 0 : meInitializationState = INITIALIZED;
663 [ # # ]: 0 : }
664 : 0 : }
665 : :
666 : :
667 : :
668 : :
669 : 0 : void MasterPageContainer::Implementation::AddChangeListener (const Link& rLink)
670 : : {
671 [ # # ]: 0 : const ::osl::MutexGuard aGuard (maMutex);
672 : :
673 : : ::std::vector<Link>::iterator iListener (
674 [ # # ]: 0 : ::std::find(maChangeListeners.begin(),maChangeListeners.end(),rLink));
675 [ # # ][ # # ]: 0 : if (iListener == maChangeListeners.end())
676 [ # # ][ # # ]: 0 : maChangeListeners.push_back(rLink);
677 : :
678 : 0 : }
679 : :
680 : :
681 : :
682 : :
683 : 0 : void MasterPageContainer::Implementation::RemoveChangeListener (const Link& rLink)
684 : : {
685 [ # # ]: 0 : const ::osl::MutexGuard aGuard (maMutex);
686 : :
687 : : ::std::vector<Link>::iterator iListener (
688 [ # # ]: 0 : ::std::find(maChangeListeners.begin(),maChangeListeners.end(),rLink));
689 [ # # ][ # # ]: 0 : if (iListener != maChangeListeners.end())
690 [ # # ][ # # ]: 0 : maChangeListeners.erase(iListener);
691 : 0 : }
692 : :
693 : :
694 : :
695 : :
696 : 0 : void MasterPageContainer::Implementation::UpdatePreviewSizePixel (void)
697 : : {
698 [ # # ]: 0 : const ::osl::MutexGuard aGuard (maMutex);
699 : :
700 : : // The default aspect ratio is 4:3
701 : 0 : int nWidth (4);
702 : 0 : int nHeight (3);
703 : :
704 : : // Search for the first entry with an existing master page.
705 : 0 : MasterPageContainerType::const_iterator iDescriptor;
706 [ # # ]: 0 : MasterPageContainerType::const_iterator iContainerEnd(maContainer.end());
707 [ # # ][ # # ]: 0 : for (iDescriptor=maContainer.begin(); iDescriptor!=iContainerEnd; ++iDescriptor)
[ # # ]
708 [ # # ][ # # ]: 0 : if (*iDescriptor!=NULL && (*iDescriptor)->mpMasterPage != NULL)
[ # # ]
709 : : {
710 [ # # ]: 0 : Size aPageSize ((*iDescriptor)->mpMasterPage->GetSize());
711 : : OSL_ASSERT(aPageSize.Width() > 0 && aPageSize.Height() > 0);
712 [ # # ]: 0 : if (aPageSize.Width() > 0)
713 : 0 : nWidth = aPageSize.Width();
714 [ # # ]: 0 : if (aPageSize.Height() > 0)
715 : 0 : nHeight = aPageSize.Height();
716 : 0 : mbFirstPageObjectSeen = true;
717 : : break;
718 : : }
719 : :
720 : 0 : maSmallPreviewSizePixel.Width() = SMALL_PREVIEW_WIDTH;
721 : 0 : maLargePreviewSizePixel.Width() = LARGE_PREVIEW_WIDTH;
722 : :
723 : 0 : int nNewSmallHeight ((maSmallPreviewSizePixel.Width()-2) * nHeight / nWidth + 2);
724 : 0 : int nNewLargeHeight ((maLargePreviewSizePixel.Width()-2) * nHeight / nWidth + 2);
725 : :
726 [ # # ]: 0 : if (nNewSmallHeight!=maSmallPreviewSizePixel.Height()
[ # # # # ]
727 : 0 : || nNewLargeHeight!=maLargePreviewSizePixel.Height())
728 : : {
729 : 0 : maSmallPreviewSizePixel.Height() = nNewSmallHeight;
730 : 0 : maLargePreviewSizePixel.Height() = nNewLargeHeight;
731 : : FireContainerChange(
732 : : MasterPageContainerChangeEvent::SIZE_CHANGED,
733 [ # # ]: 0 : NIL_TOKEN);
734 [ # # ]: 0 : }
735 : 0 : }
736 : :
737 : :
738 : :
739 : :
740 : 0 : Size MasterPageContainer::Implementation::GetPreviewSizePixel (PreviewSize eSize) const
741 : : {
742 [ # # ]: 0 : if (eSize == SMALL)
743 : 0 : return maSmallPreviewSizePixel;
744 : : else
745 : 0 : return maLargePreviewSizePixel;
746 : : }
747 : :
748 : :
749 : :
750 : :
751 : 0 : IMPL_LINK(MasterPageContainer::Implementation,AsynchronousNotifyCallback, EventData*, pData)
752 : : {
753 [ # # ]: 0 : const ::osl::MutexGuard aGuard (maMutex);
754 : :
755 [ # # ]: 0 : if (pData != NULL)
756 : : {
757 [ # # ]: 0 : FireContainerChange(pData->first, pData->second, false);
758 : 0 : delete pData;
759 : : }
760 : :
761 [ # # ]: 0 : return 0;
762 : : }
763 : :
764 : :
765 : :
766 : :
767 : 0 : MasterPageContainer::Token MasterPageContainer::Implementation::PutMasterPage (
768 : : const SharedMasterPageDescriptor& rpDescriptor)
769 : : {
770 [ # # ]: 0 : const ::osl::MutexGuard aGuard (maMutex);
771 : :
772 : 0 : Token aResult (NIL_TOKEN);
773 : :
774 : : // Get page object and preview when that is inexpensive.
775 [ # # ]: 0 : UpdateDescriptor(rpDescriptor,false,false, false);
776 : :
777 : : // Look up the new MasterPageDescriptor and either insert it or update
778 : : // an already existing one.
779 : : MasterPageContainerType::iterator aEntry (
780 : : ::std::find_if (
781 : : maContainer.begin(),
782 : : maContainer.end(),
783 [ # # ][ # # ]: 0 : MasterPageDescriptor::AllComparator(rpDescriptor)));
[ # # ]
784 [ # # ][ # # ]: 0 : if (aEntry == maContainer.end())
785 : : {
786 : : // Insert a new MasterPageDescriptor.
787 : 0 : bool bIgnore (rpDescriptor->mpPageObjectProvider.get()==NULL
788 [ # # ][ # # ]: 0 : && rpDescriptor->msURL.isEmpty());
789 : :
790 [ # # ]: 0 : if ( ! bIgnore)
791 : : {
792 [ # # ]: 0 : if (mbContainerCleaningPending)
793 [ # # ]: 0 : CleanContainer();
794 : :
795 : 0 : aResult = maContainer.size();
796 [ # # ]: 0 : rpDescriptor->SetToken(aResult);
797 : :
798 : : // Templates are precious, i.e. we lock them so that they will
799 : : // not be destroyed when (temporarily) no one references them.
800 : : // They will only be deleted when the container is destroyed.
801 [ # # ]: 0 : switch (rpDescriptor->meOrigin)
802 : : {
803 : : case TEMPLATE:
804 : : case DEFAULT:
805 : 0 : ++rpDescriptor->mnUseCount;
806 : 0 : break;
807 : :
808 : : default:
809 : 0 : break;
810 : : }
811 : :
812 [ # # ]: 0 : maContainer.push_back(rpDescriptor);
813 [ # # ]: 0 : aEntry = maContainer.end()-1;
814 : :
815 [ # # ]: 0 : FireContainerChange(MasterPageContainerChangeEvent::CHILD_ADDED,aResult);
816 : : }
817 : : }
818 : : else
819 : : {
820 : : // Update an existing MasterPageDescriptor.
821 : 0 : aResult = (*aEntry)->maToken;
822 : : ::std::auto_ptr<std::vector<MasterPageContainerChangeEvent::EventType> > pEventTypes(
823 [ # # ][ # # ]: 0 : (*aEntry)->Update(*rpDescriptor));
824 [ # # ][ # # ]: 0 : if (pEventTypes.get()!=NULL && pEventTypes->size()>0)
[ # # ]
825 : : {
826 : : // One or more aspects of the descriptor have changed. Send
827 : : // appropriate events to the listeners.
828 [ # # ]: 0 : UpdateDescriptor(*aEntry,false,false, true);
829 : :
830 : 0 : std::vector<MasterPageContainerChangeEvent::EventType>::const_iterator iEventType;
831 [ # # ][ # # ]: 0 : for (iEventType=pEventTypes->begin(); iEventType!=pEventTypes->end(); ++iEventType)
[ # # ][ # # ]
832 : : {
833 : : FireContainerChange(
834 [ # # ]: 0 : *iEventType,
835 : 0 : (*aEntry)->maToken,
836 [ # # ]: 0 : false);
837 : : }
838 [ # # ]: 0 : }
839 : : }
840 : :
841 [ # # ]: 0 : return aResult;
842 : : }
843 : :
844 : :
845 : :
846 : :
847 : 0 : bool MasterPageContainer::Implementation::HasToken (Token aToken) const
848 : : {
849 : : return aToken>=0
850 : 0 : && (unsigned)aToken<maContainer.size()
851 [ # # # # ]: 0 : && maContainer[aToken].get()!=NULL;
[ # # ]
852 : : }
853 : :
854 : :
855 : :
856 : :
857 : 0 : const SharedMasterPageDescriptor MasterPageContainer::Implementation::GetDescriptor (
858 : : Token aToken) const
859 : : {
860 [ # # ][ # # ]: 0 : if (aToken>=0 && (unsigned)aToken<maContainer.size())
[ # # ]
861 : 0 : return maContainer[aToken];
862 : : else
863 : 0 : return SharedMasterPageDescriptor();
864 : : }
865 : :
866 : :
867 : :
868 : :
869 : 0 : SharedMasterPageDescriptor MasterPageContainer::Implementation::GetDescriptor (Token aToken)
870 : : {
871 [ # # ][ # # ]: 0 : if (aToken>=0 && (unsigned)aToken<maContainer.size())
[ # # ]
872 : 0 : return maContainer[aToken];
873 : : else
874 : 0 : return SharedMasterPageDescriptor();
875 : : }
876 : :
877 : :
878 : :
879 : :
880 : 0 : void MasterPageContainer::Implementation::InvalidatePreview (Token aToken)
881 : : {
882 [ # # ]: 0 : const ::osl::MutexGuard aGuard (maMutex);
883 : :
884 [ # # ]: 0 : SharedMasterPageDescriptor pDescriptor (GetDescriptor(aToken));
885 [ # # ]: 0 : if (pDescriptor.get() != NULL)
886 : : {
887 [ # # ][ # # ]: 0 : pDescriptor->maSmallPreview = Image();
[ # # ]
888 [ # # ][ # # ]: 0 : pDescriptor->maLargePreview = Image();
[ # # ]
889 [ # # ]: 0 : RequestPreview(aToken);
890 [ # # ][ # # ]: 0 : }
891 : 0 : }
892 : :
893 : :
894 : :
895 : :
896 : 0 : Image MasterPageContainer::Implementation::GetPreviewForToken (
897 : : MasterPageContainer::Token aToken,
898 : : PreviewSize ePreviewSize)
899 : : {
900 [ # # ]: 0 : const ::osl::MutexGuard aGuard (maMutex);
901 : :
902 [ # # ]: 0 : Image aPreview;
903 [ # # ]: 0 : PreviewState ePreviewState (GetPreviewState(aToken));
904 : :
905 [ # # ]: 0 : SharedMasterPageDescriptor pDescriptor = GetDescriptor(aToken);
906 : :
907 : : // When the preview is missing but inexpensively creatable then do that
908 : : // now.
909 [ # # ]: 0 : if (pDescriptor.get()!=NULL)
910 : : {
911 [ # # ]: 0 : if (ePreviewState == PS_CREATABLE)
912 [ # # ][ # # ]: 0 : if (UpdateDescriptor(pDescriptor, false,false, true))
913 [ # # ][ # # ]: 0 : if (pDescriptor->maLargePreview.GetSizePixel().Width() != 0)
914 : 0 : ePreviewState = PS_AVAILABLE;
915 : :
916 [ # # # # : 0 : switch (ePreviewState)
# ]
917 : : {
918 : : case PS_AVAILABLE:
919 [ # # ][ # # ]: 0 : aPreview = pDescriptor->GetPreview(ePreviewSize);
[ # # ]
920 : 0 : break;
921 : :
922 : : case PS_PREPARING:
923 : : aPreview = GetPreviewSubstitution(
924 : : STR_TASKPANEL_PREPARING_PREVIEW_SUBSTITUTION,
925 [ # # ][ # # ]: 0 : ePreviewSize);
[ # # ]
926 : 0 : break;
927 : :
928 : : case PS_CREATABLE:
929 : : aPreview = GetPreviewSubstitution(
930 : : STR_TASKPANEL_PREPARING_PREVIEW_SUBSTITUTION,
931 [ # # ][ # # ]: 0 : ePreviewSize);
[ # # ]
932 : 0 : break;
933 : :
934 : : case PS_NOT_AVAILABLE:
935 : : aPreview = GetPreviewSubstitution(
936 : : STR_TASKPANEL_NOT_AVAILABLE_SUBSTITUTION,
937 [ # # ][ # # ]: 0 : ePreviewSize);
[ # # ]
938 [ # # ]: 0 : if (ePreviewSize == SMALL)
939 [ # # ]: 0 : pDescriptor->maSmallPreview = aPreview;
940 : : else
941 [ # # ]: 0 : pDescriptor->maLargePreview = aPreview;
942 : 0 : break;
943 : : }
944 : : }
945 : :
946 [ # # ][ # # ]: 0 : return aPreview;
947 : : }
948 : :
949 : :
950 : :
951 : :
952 : 0 : MasterPageContainer::PreviewState MasterPageContainer::Implementation::GetPreviewState (
953 : : Token aToken) const
954 : : {
955 [ # # ]: 0 : const ::osl::MutexGuard aGuard (maMutex);
956 : :
957 : 0 : PreviewState eState (PS_NOT_AVAILABLE);
958 : :
959 [ # # ]: 0 : SharedMasterPageDescriptor pDescriptor = GetDescriptor(aToken);
960 [ # # ]: 0 : if (pDescriptor.get() != NULL)
961 : : {
962 [ # # ][ # # ]: 0 : if (pDescriptor->maLargePreview.GetSizePixel().Width() != 0)
963 : 0 : eState = PS_AVAILABLE;
964 [ # # ]: 0 : else if (pDescriptor->mpPreviewProvider.get() != NULL)
965 : : {
966 : : // The preview does not exist but can be created. When that is
967 : : // not expensive then do it at once.
968 [ # # ][ # # ]: 0 : if (mpRequestQueue->HasRequest(aToken))
969 : 0 : eState = PS_PREPARING;
970 : : else
971 : 0 : eState = PS_CREATABLE;
972 : : }
973 : : else
974 : 0 : eState = PS_NOT_AVAILABLE;
975 : : }
976 : :
977 [ # # ][ # # ]: 0 : return eState;
978 : : }
979 : :
980 : :
981 : :
982 : :
983 : 0 : bool MasterPageContainer::Implementation::RequestPreview (Token aToken)
984 : : {
985 [ # # ]: 0 : SharedMasterPageDescriptor pDescriptor = GetDescriptor(aToken);
986 [ # # ]: 0 : if (pDescriptor.get() != NULL)
987 [ # # ]: 0 : return mpRequestQueue->RequestPreview(pDescriptor);
988 : : else
989 [ # # ]: 0 : return false;
990 : : }
991 : :
992 : :
993 : :
994 : :
995 : 0 : Reference<frame::XModel> MasterPageContainer::Implementation::GetModel (void)
996 : : {
997 [ # # ]: 0 : const ::osl::MutexGuard aGuard (maMutex);
998 : :
999 [ # # ]: 0 : if ( ! mxModel.is())
1000 : : {
1001 : : // Get the desktop a s service factory.
1002 : 0 : ::rtl::OUString sDesktopServiceName ( "com.sun.star.frame.Desktop");
1003 : : uno::Reference<frame::XComponentLoader> xDesktop (
1004 [ # # ][ # # ]: 0 : ::comphelper::getProcessServiceFactory()->createInstance(
1005 : 0 : sDesktopServiceName),
1006 [ # # ][ # # ]: 0 : uno::UNO_QUERY);
1007 : :
1008 : : // Create a new model.
1009 : 0 : ::rtl::OUString sModelServiceName ( "com.sun.star.presentation.PresentationDocument");
1010 : : mxModel = uno::Reference<frame::XModel>(
1011 [ # # ][ # # ]: 0 : ::comphelper::getProcessServiceFactory()->createInstance(
1012 : 0 : sModelServiceName),
1013 [ # # ][ # # ]: 0 : uno::UNO_QUERY);
[ # # ]
1014 : :
1015 : : // Initialize the model.
1016 [ # # ]: 0 : uno::Reference<frame::XLoadable> xLoadable (mxModel,uno::UNO_QUERY);
1017 [ # # ]: 0 : if (xLoadable.is())
1018 [ # # ][ # # ]: 0 : xLoadable->initNew();
1019 : :
1020 : : // Use its tunnel to get a pointer to its core implementation.
1021 [ # # ]: 0 : uno::Reference<lang::XUnoTunnel> xUnoTunnel (mxModel, uno::UNO_QUERY);
1022 [ # # ]: 0 : if (xUnoTunnel.is())
1023 : : {
1024 : : mpDocument = reinterpret_cast<SdXImpressDocument*>(
1025 [ # # ]: 0 : xUnoTunnel->getSomething(
1026 [ # # ]: 0 : SdXImpressDocument::getUnoTunnelId()))->GetDoc();
1027 : : }
1028 : :
1029 : : // Create a default page.
1030 [ # # ]: 0 : uno::Reference<drawing::XDrawPagesSupplier> xSlideSupplier (mxModel, uno::UNO_QUERY);
1031 [ # # ]: 0 : if (xSlideSupplier.is())
1032 : : {
1033 : : uno::Reference<drawing::XDrawPages> xSlides (
1034 [ # # ][ # # ]: 0 : xSlideSupplier->getDrawPages(), uno::UNO_QUERY);
[ # # ]
1035 [ # # ]: 0 : if (xSlides.is())
1036 : : {
1037 : 0 : sal_Int32 nIndex (0);
1038 [ # # ][ # # ]: 0 : uno::Reference<drawing::XDrawPage> xNewPage (xSlides->insertNewByIndex(nIndex));
1039 [ # # ]: 0 : uno::Reference<beans::XPropertySet> xProperties(xNewPage, uno::UNO_QUERY);
1040 [ # # ]: 0 : if (xProperties.is())
1041 [ # # ]: 0 : xProperties->setPropertyValue(
1042 : : "Layout",
1043 [ # # ][ # # ]: 0 : makeAny((sal_Int16)AUTOLAYOUT_TITLE));
1044 : 0 : }
1045 : 0 : }
1046 : : }
1047 [ # # ]: 0 : return mxModel;
1048 : : }
1049 : :
1050 : :
1051 : :
1052 : :
1053 : 0 : SdDrawDocument* MasterPageContainer::Implementation::GetDocument (void)
1054 : : {
1055 : 0 : GetModel();
1056 : 0 : return mpDocument;
1057 : : }
1058 : :
1059 : :
1060 : :
1061 : :
1062 : 0 : Image MasterPageContainer::Implementation::GetPreviewSubstitution (
1063 : : sal_uInt16 nId,
1064 : : PreviewSize ePreviewSize)
1065 : : {
1066 [ # # ]: 0 : const ::osl::MutexGuard aGuard (maMutex);
1067 : :
1068 [ # # ]: 0 : Image aPreview;
1069 : :
1070 [ # # # ]: 0 : switch (nId)
1071 : : {
1072 : : case STR_TASKPANEL_PREPARING_PREVIEW_SUBSTITUTION:
1073 : : {
1074 : : Image& rPreview (ePreviewSize==SMALL
1075 : : ? maSmallPreviewBeingCreated
1076 [ # # ]: 0 : : maLargePreviewBeingCreated);
1077 [ # # ][ # # ]: 0 : if (rPreview.GetSizePixel().Width() == 0)
1078 : : {
1079 : : rPreview = maPreviewRenderer.RenderSubstitution(
1080 : : ePreviewSize==SMALL ? maSmallPreviewSizePixel : maLargePreviewSizePixel,
1081 [ # # ][ # # ]: 0 : SdResId(STR_TASKPANEL_PREPARING_PREVIEW_SUBSTITUTION));
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
1082 : : }
1083 [ # # ]: 0 : aPreview = rPreview;
1084 : : }
1085 : 0 : break;
1086 : :
1087 : : case STR_TASKPANEL_NOT_AVAILABLE_SUBSTITUTION:
1088 : : {
1089 : : Image& rPreview (ePreviewSize==SMALL
1090 : : ? maSmallPreviewNotAvailable
1091 [ # # ]: 0 : : maLargePreviewNotAvailable);
1092 [ # # ][ # # ]: 0 : if (rPreview.GetSizePixel().Width() == 0)
1093 : : {
1094 : : rPreview = maPreviewRenderer.RenderSubstitution(
1095 : : ePreviewSize==SMALL ? maSmallPreviewSizePixel : maLargePreviewSizePixel,
1096 [ # # ][ # # ]: 0 : SdResId(STR_TASKPANEL_NOT_AVAILABLE_SUBSTITUTION));
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
1097 : : }
1098 [ # # ]: 0 : aPreview = rPreview;
1099 : : }
1100 : 0 : break;
1101 : : }
1102 : :
1103 [ # # ]: 0 : return aPreview;
1104 : : }
1105 : :
1106 : :
1107 : :
1108 : :
1109 : 0 : void MasterPageContainer::Implementation::CleanContainer (void)
1110 : : {
1111 : : // Remove the empty elements at the end of the container. The empty
1112 : : // elements in the middle can not be removed because that would
1113 : : // invalidate the references still held by others.
1114 : 0 : int nIndex (maContainer.size()-1);
1115 [ # # ][ # # ]: 0 : while (nIndex>=0 && maContainer[nIndex].get()==NULL)
[ # # ]
1116 : 0 : --nIndex;
1117 : 0 : maContainer.resize(++nIndex);
1118 : 0 : }
1119 : :
1120 : :
1121 : :
1122 : :
1123 : 0 : void MasterPageContainer::Implementation::FireContainerChange (
1124 : : MasterPageContainerChangeEvent::EventType eType,
1125 : : Token aToken,
1126 : : bool bNotifyAsynchronously)
1127 : : {
1128 [ # # ]: 0 : if (bNotifyAsynchronously)
1129 : : {
1130 : : Application::PostUserEvent(
1131 : : LINK(this,Implementation,AsynchronousNotifyCallback),
1132 [ # # ][ # # ]: 0 : new EventData(eType,aToken));
1133 : : }
1134 : : else
1135 : : {
1136 [ # # ]: 0 : ::std::vector<Link> aCopy(maChangeListeners.begin(),maChangeListeners.end());
1137 : 0 : ::std::vector<Link>::iterator iListener;
1138 : : MasterPageContainerChangeEvent aEvent;
1139 : 0 : aEvent.meEventType = eType;
1140 : 0 : aEvent.maChildToken = aToken;
1141 [ # # ][ # # ]: 0 : for (iListener=aCopy.begin(); iListener!=aCopy.end(); ++iListener)
[ # # ]
1142 [ # # ][ # # ]: 0 : iListener->Call(&aEvent);
1143 : : }
1144 : 0 : }
1145 : :
1146 : :
1147 : :
1148 : :
1149 : 0 : bool MasterPageContainer::Implementation::UpdateDescriptor (
1150 : : const SharedMasterPageDescriptor& rpDescriptor,
1151 : : bool bForcePageObject,
1152 : : bool bForcePreview,
1153 : : bool bSendEvents)
1154 : : {
1155 [ # # ]: 0 : const ::osl::MutexGuard aGuard (maMutex);
1156 : :
1157 : : // We have to create the page object when the preview provider needs it
1158 : : // and the caller needs the preview.
1159 : : bForcePageObject |= (bForcePreview
1160 [ # # ]: 0 : && rpDescriptor->mpPreviewProvider->NeedsPageObject()
1161 [ # # ][ # # ]: 0 : && rpDescriptor->mpMasterPage==NULL);
[ # # ]
1162 : :
1163 : : // Define a cost threshold so that an update or page object or preview
1164 : : // that is at least this cost are made at once. Updates with higher cost
1165 : : // are scheduled for later.
1166 [ # # ][ # # ]: 0 : sal_Int32 nCostThreshold (mpRequestQueue->IsEmpty() ? 5 : 0);
1167 : :
1168 : : // Update the page object (which may be used for the preview update).
1169 [ # # ]: 0 : if (bForcePageObject)
1170 [ # # ]: 0 : GetDocument();
1171 : : bool bPageObjectModified (rpDescriptor->UpdatePageObject(
1172 : : (bForcePageObject ? -1 : nCostThreshold),
1173 [ # # ][ # # ]: 0 : mpDocument));
1174 [ # # ][ # # ]: 0 : if (bPageObjectModified && bSendEvents)
1175 : : FireContainerChange(
1176 : : MasterPageContainerChangeEvent::DATA_CHANGED,
1177 [ # # ]: 0 : rpDescriptor->maToken);
1178 [ # # ][ # # ]: 0 : if (bPageObjectModified && ! mbFirstPageObjectSeen)
1179 [ # # ]: 0 : UpdatePreviewSizePixel();
1180 : :
1181 : : // Update the preview.
1182 : : bool bPreviewModified (rpDescriptor->UpdatePreview(
1183 : : (bForcePreview ? -1 : nCostThreshold),
1184 : : maSmallPreviewSizePixel,
1185 : : maLargePreviewSizePixel,
1186 [ # # ][ # # ]: 0 : maPreviewRenderer));
1187 : :
1188 [ # # ][ # # ]: 0 : if (bPreviewModified && bSendEvents)
1189 : : FireContainerChange(
1190 : : MasterPageContainerChangeEvent::PREVIEW_CHANGED,
1191 [ # # ]: 0 : rpDescriptor->maToken);
1192 : :
1193 [ # # ][ # # ]: 0 : return bPageObjectModified || bPreviewModified;
[ # # ]
1194 : : }
1195 : :
1196 : :
1197 : :
1198 : :
1199 : 0 : void MasterPageContainer::Implementation::ReleaseDescriptor (Token aToken)
1200 : : {
1201 [ # # ][ # # ]: 0 : if (aToken>=0 && (unsigned)aToken<maContainer.size())
[ # # ]
1202 : : {
1203 : 0 : maContainer[aToken].reset();
1204 : 0 : mbContainerCleaningPending = true;
1205 : : }
1206 : 0 : }
1207 : :
1208 : :
1209 : :
1210 : :
1211 : 0 : void MasterPageContainer::Implementation::FillingDone (void)
1212 : : {
1213 : 0 : mpRequestQueue->ProcessAllRequests();
1214 : 0 : }
1215 : :
1216 : :
1217 : :
1218 [ + - ][ + - ]: 75 : } } } // end of namespace ::sd::toolpanel::controls
1219 : :
1220 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|