xref: /AOO41X/main/sd/source/ui/sidebar/MasterPageContainer.cxx (revision b862c97c327d912ac6f569bb343850715f80ed9c)
102c50d82SAndre Fischer /**************************************************************
202c50d82SAndre Fischer  *
302c50d82SAndre Fischer  * Licensed to the Apache Software Foundation (ASF) under one
402c50d82SAndre Fischer  * or more contributor license agreements.  See the NOTICE file
502c50d82SAndre Fischer  * distributed with this work for additional information
602c50d82SAndre Fischer  * regarding copyright ownership.  The ASF licenses this file
702c50d82SAndre Fischer  * to you under the Apache License, Version 2.0 (the
802c50d82SAndre Fischer  * "License"); you may not use this file except in compliance
902c50d82SAndre Fischer  * with the License.  You may obtain a copy of the License at
1002c50d82SAndre Fischer  *
1102c50d82SAndre Fischer  *   http://www.apache.org/licenses/LICENSE-2.0
1202c50d82SAndre Fischer  *
1302c50d82SAndre Fischer  * Unless required by applicable law or agreed to in writing,
1402c50d82SAndre Fischer  * software distributed under the License is distributed on an
1502c50d82SAndre Fischer  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1602c50d82SAndre Fischer  * KIND, either express or implied.  See the License for the
1702c50d82SAndre Fischer  * specific language governing permissions and limitations
1802c50d82SAndre Fischer  * under the License.
1902c50d82SAndre Fischer  *
2002c50d82SAndre Fischer  *************************************************************/
2102c50d82SAndre Fischer 
2202c50d82SAndre Fischer #include "precompiled_sd.hxx"
2302c50d82SAndre Fischer 
2402c50d82SAndre Fischer #include "MasterPageContainer.hxx"
2502c50d82SAndre Fischer 
2602c50d82SAndre Fischer #include "MasterPageDescriptor.hxx"
2702c50d82SAndre Fischer #include "MasterPageContainerFiller.hxx"
2802c50d82SAndre Fischer #include "MasterPageContainerQueue.hxx"
2902c50d82SAndre Fischer #include "TemplateScanner.hxx"
3002c50d82SAndre Fischer #include "tools/AsynchronousTask.hxx"
3102c50d82SAndre Fischer #include "strings.hrc"
3202c50d82SAndre Fischer #include <algorithm>
3302c50d82SAndre Fischer #include <list>
3402c50d82SAndre Fischer #include <set>
3502c50d82SAndre Fischer 
3602c50d82SAndre Fischer #include "unomodel.hxx"
3702c50d82SAndre Fischer #include <com/sun/star/frame/XComponentLoader.hpp>
3802c50d82SAndre Fischer #include <com/sun/star/io/XStream.hpp>
3902c50d82SAndre Fischer #include <com/sun/star/io/XInputStream.hpp>
4002c50d82SAndre Fischer #include <com/sun/star/lang/XSingleServiceFactory.hpp>
4102c50d82SAndre Fischer #include <com/sun/star/lang/XMultiServiceFactory.hpp>
4202c50d82SAndre Fischer #include <com/sun/star/uno/Reference.hxx>
4302c50d82SAndre Fischer #include <com/sun/star/uno/Any.hxx>
4402c50d82SAndre Fischer #include <com/sun/star/uno/Sequence.hxx>
4502c50d82SAndre Fischer #include <com/sun/star/util/XCloseable.hpp>
4602c50d82SAndre Fischer #include <comphelper/processfactory.hxx>
4702c50d82SAndre Fischer #include <tools/urlobj.hxx>
4802c50d82SAndre Fischer #include <sfx2/app.hxx>
4902c50d82SAndre Fischer #include <svx/svdpage.hxx>
5002c50d82SAndre Fischer #include "DrawDocShell.hxx"
5102c50d82SAndre Fischer #include "drawdoc.hxx"
5202c50d82SAndre Fischer #include "sdpage.hxx"
5302c50d82SAndre Fischer #include <svl/itemset.hxx>
5402c50d82SAndre Fischer #include <svl/eitem.hxx>
5502c50d82SAndre Fischer #include "sdresid.hxx"
5602c50d82SAndre Fischer #include "tools/TimerBasedTaskExecution.hxx"
5702c50d82SAndre Fischer #include "pres.hxx"
5802c50d82SAndre Fischer #include <osl/mutex.hxx>
5902c50d82SAndre Fischer #include <boost/weak_ptr.hpp>
6002c50d82SAndre Fischer 
6102c50d82SAndre Fischer using namespace ::com::sun::star;
6202c50d82SAndre Fischer using namespace ::com::sun::star::uno;
6302c50d82SAndre Fischer 
6402c50d82SAndre Fischer namespace {
6502c50d82SAndre Fischer 
6602c50d82SAndre Fischer typedef ::std::vector<sd::sidebar::SharedMasterPageDescriptor> MasterPageContainerType;
6702c50d82SAndre Fischer 
6802c50d82SAndre Fischer } // end of anonymous namespace
6902c50d82SAndre Fischer 
7002c50d82SAndre Fischer 
7102c50d82SAndre Fischer namespace sd { namespace sidebar {
7202c50d82SAndre Fischer 
7302c50d82SAndre Fischer 
7402c50d82SAndre Fischer /** Inner implementation class of the MasterPageContainer.
7502c50d82SAndre Fischer */
7602c50d82SAndre Fischer class MasterPageContainer::Implementation
7702c50d82SAndre Fischer     : public SdGlobalResource,
7802c50d82SAndre Fischer       public MasterPageContainerFiller::ContainerAdapter,
7902c50d82SAndre Fischer       public MasterPageContainerQueue::ContainerAdapter
8002c50d82SAndre Fischer {
8102c50d82SAndre Fischer public:
8202c50d82SAndre Fischer     mutable ::osl::Mutex maMutex;
8302c50d82SAndre Fischer 
8402c50d82SAndre Fischer     static ::boost::weak_ptr<Implementation> mpInstance;
8502c50d82SAndre Fischer     MasterPageContainerType maContainer;
8602c50d82SAndre Fischer 
8702c50d82SAndre Fischer     static ::boost::shared_ptr<Implementation> Instance (void);
8802c50d82SAndre Fischer 
8902c50d82SAndre Fischer     void LateInit (void);
9002c50d82SAndre Fischer     void AddChangeListener (const Link& rLink);
9102c50d82SAndre Fischer     void RemoveChangeListener (const Link& rLink);
9202c50d82SAndre Fischer     void UpdatePreviewSizePixel (void);
9302c50d82SAndre Fischer     Size GetPreviewSizePixel (PreviewSize eSize) const;
9402c50d82SAndre Fischer 
9502c50d82SAndre Fischer     bool HasToken (Token aToken) const;
9602c50d82SAndre Fischer     const SharedMasterPageDescriptor GetDescriptor (MasterPageContainer::Token aToken) const;
9702c50d82SAndre Fischer     SharedMasterPageDescriptor GetDescriptor (MasterPageContainer::Token aToken);
9802c50d82SAndre Fischer     virtual Token PutMasterPage (const SharedMasterPageDescriptor& rDescriptor);
9902c50d82SAndre Fischer     void InvalidatePreview (Token aToken);
10002c50d82SAndre Fischer     Image GetPreviewForToken (
10102c50d82SAndre Fischer         Token aToken,
10202c50d82SAndre Fischer         PreviewSize ePreviewSize);
10302c50d82SAndre Fischer     PreviewState GetPreviewState (Token aToken) const;
10402c50d82SAndre Fischer     bool RequestPreview (Token aToken);
10502c50d82SAndre Fischer 
10602c50d82SAndre Fischer     Reference<frame::XModel> GetModel (void);
10702c50d82SAndre Fischer     SdDrawDocument* GetDocument (void);
10802c50d82SAndre Fischer 
10902c50d82SAndre Fischer     void FireContainerChange (
11002c50d82SAndre Fischer         MasterPageContainerChangeEvent::EventType eType,
11102c50d82SAndre Fischer         Token aToken,
11202c50d82SAndre Fischer         bool bNotifyAsynchronously = false);
11302c50d82SAndre Fischer 
11402c50d82SAndre Fischer     virtual bool UpdateDescriptor (
11502c50d82SAndre Fischer         const SharedMasterPageDescriptor& rpDescriptor,
11602c50d82SAndre Fischer         bool bForcePageObject,
11702c50d82SAndre Fischer         bool bForcePreview,
11802c50d82SAndre Fischer         bool bSendEvents);
11902c50d82SAndre Fischer 
12002c50d82SAndre Fischer     void ReleaseDescriptor (Token aToken);
12102c50d82SAndre Fischer 
12202c50d82SAndre Fischer     /** Called by the MasterPageContainerFiller to notify that all master
12302c50d82SAndre Fischer         pages from template documents have been added.
12402c50d82SAndre Fischer     */
12502c50d82SAndre Fischer     virtual void FillingDone (void);
12602c50d82SAndre Fischer 
12702c50d82SAndre Fischer private:
12802c50d82SAndre Fischer     Implementation (void);
12902c50d82SAndre Fischer     virtual ~Implementation (void);
13002c50d82SAndre Fischer 
13102c50d82SAndre Fischer     class Deleter { public:
operator ()(Implementation * pObject)13202c50d82SAndre Fischer         void operator() (Implementation* pObject) { delete pObject; }
13302c50d82SAndre Fischer     };
13402c50d82SAndre Fischer     friend class Deleter;
13502c50d82SAndre Fischer 
13602c50d82SAndre Fischer     enum InitializationState { NOT_INITIALIZED, INITIALIZING, INITIALIZED } meInitializationState;
13702c50d82SAndre Fischer 
13802c50d82SAndre Fischer     ::boost::scoped_ptr<MasterPageContainerQueue> mpRequestQueue;
13902c50d82SAndre Fischer     ::com::sun::star::uno::Reference<com::sun::star::frame::XModel> mxModel;
14002c50d82SAndre Fischer     SdDrawDocument* mpDocument;
14102c50d82SAndre Fischer     PreviewRenderer maPreviewRenderer;
14202c50d82SAndre Fischer     /** Remember whether the first page object has already been used to
14302c50d82SAndre Fischer         determine the correct size ratio.
14402c50d82SAndre Fischer     */
14502c50d82SAndre Fischer     bool mbFirstPageObjectSeen;
14602c50d82SAndre Fischer 
14702c50d82SAndre Fischer     // The widths for the previews contain two pixels for the border that is
14802c50d82SAndre Fischer     // painted arround the preview.
14902c50d82SAndre Fischer     static const int SMALL_PREVIEW_WIDTH = 72 + 2;
15002c50d82SAndre Fischer     static const int LARGE_PREVIEW_WIDTH = 2*72 + 2;
15102c50d82SAndre Fischer 
15202c50d82SAndre Fischer     /** This substition of page preview shows "Preparing preview" and is
15302c50d82SAndre Fischer         shown as long as the actual previews are not being present.
15402c50d82SAndre Fischer     */
15502c50d82SAndre Fischer     Image maLargePreviewBeingCreated;
15602c50d82SAndre Fischer     Image maSmallPreviewBeingCreated;
15702c50d82SAndre Fischer 
15802c50d82SAndre Fischer     /** This substition of page preview is shown when a preview can not be
15902c50d82SAndre Fischer         created and thus is not available.
16002c50d82SAndre Fischer     */
16102c50d82SAndre Fischer     Image maLargePreviewNotAvailable;
16202c50d82SAndre Fischer     Image maSmallPreviewNotAvailable;
16302c50d82SAndre Fischer 
16402c50d82SAndre Fischer     ::std::vector<Link> maChangeListeners;
16502c50d82SAndre Fischer 
16602c50d82SAndre Fischer     // We have to remember the tasks for initialization and filling in case
16702c50d82SAndre Fischer     // a MasterPageContainer object is destroyed before these tasks have
16802c50d82SAndre Fischer     // been completed.
16902c50d82SAndre Fischer     ::boost::weak_ptr<sd::tools::TimerBasedTaskExecution> mpFillerTask;
17002c50d82SAndre Fischer 
17102c50d82SAndre Fischer     Size maSmallPreviewSizePixel;
17202c50d82SAndre Fischer     Size maLargePreviewSizePixel;
17302c50d82SAndre Fischer     bool mbPageRatioKnown;
17402c50d82SAndre Fischer 
17502c50d82SAndre Fischer     bool mbContainerCleaningPending;
17602c50d82SAndre Fischer 
17702c50d82SAndre Fischer     typedef ::std::pair<MasterPageContainerChangeEvent::EventType,Token> EventData;
17802c50d82SAndre Fischer     DECL_LINK(AsynchronousNotifyCallback, EventData*);
17902c50d82SAndre Fischer     ::sd::DrawDocShell* LoadDocument (
18002c50d82SAndre Fischer         const String& sFileName,
18102c50d82SAndre Fischer         SfxObjectShellLock& rxDocumentShell);
18202c50d82SAndre Fischer 
18302c50d82SAndre Fischer     Image GetPreviewSubstitution (sal_uInt16 nId, PreviewSize ePreviewSize);
18402c50d82SAndre Fischer 
18502c50d82SAndre Fischer     void CleanContainer (void);
18602c50d82SAndre Fischer };
18702c50d82SAndre Fischer 
18802c50d82SAndre Fischer 
18902c50d82SAndre Fischer 
19002c50d82SAndre Fischer 
19102c50d82SAndre Fischer //===== MasterPageContainer ===================================================
19202c50d82SAndre Fischer 
19302c50d82SAndre Fischer ::boost::weak_ptr<MasterPageContainer::Implementation>
19402c50d82SAndre Fischer     MasterPageContainer::Implementation::mpInstance;
19502c50d82SAndre Fischer static const MasterPageContainer::Token NIL_TOKEN (-1);
19602c50d82SAndre Fischer 
19702c50d82SAndre Fischer 
19802c50d82SAndre Fischer 
19902c50d82SAndre Fischer 
20002c50d82SAndre Fischer ::boost::shared_ptr<MasterPageContainer::Implementation>
Instance(void)20102c50d82SAndre Fischer     MasterPageContainer::Implementation::Instance (void)
20202c50d82SAndre Fischer {
20302c50d82SAndre Fischer     ::boost::shared_ptr<MasterPageContainer::Implementation> pInstance;
20402c50d82SAndre Fischer 
20502c50d82SAndre Fischer     if (Implementation::mpInstance.expired())
20602c50d82SAndre Fischer     {
20702c50d82SAndre Fischer         ::osl::GetGlobalMutex aMutexFunctor;
20802c50d82SAndre Fischer         ::osl::MutexGuard aGuard (aMutexFunctor());
20902c50d82SAndre Fischer         if (Implementation::mpInstance.expired())
21002c50d82SAndre Fischer         {
21102c50d82SAndre Fischer             OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
21202c50d82SAndre Fischer             pInstance = ::boost::shared_ptr<MasterPageContainer::Implementation>(
21302c50d82SAndre Fischer                 new MasterPageContainer::Implementation(),
21402c50d82SAndre Fischer                 MasterPageContainer::Implementation::Deleter());
21502c50d82SAndre Fischer             SdGlobalResourceContainer::Instance().AddResource(pInstance);
21602c50d82SAndre Fischer             Implementation::mpInstance = pInstance;
21702c50d82SAndre Fischer         }
21802c50d82SAndre Fischer         else
21902c50d82SAndre Fischer             pInstance = ::boost::shared_ptr<MasterPageContainer::Implementation>(
22002c50d82SAndre Fischer                 Implementation::mpInstance);
22102c50d82SAndre Fischer     }
22202c50d82SAndre Fischer     else
22302c50d82SAndre Fischer     {
22402c50d82SAndre Fischer         OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
22502c50d82SAndre Fischer         pInstance = ::boost::shared_ptr<MasterPageContainer::Implementation>(
22602c50d82SAndre Fischer             Implementation::mpInstance);
22702c50d82SAndre Fischer     }
22802c50d82SAndre Fischer 
22902c50d82SAndre Fischer     DBG_ASSERT (pInstance.get()!=NULL,
23002c50d82SAndre Fischer         "MasterPageContainer::Implementation::Instance(): instance is NULL");
23102c50d82SAndre Fischer     return pInstance;
23202c50d82SAndre Fischer }
23302c50d82SAndre Fischer 
23402c50d82SAndre Fischer 
23502c50d82SAndre Fischer 
23602c50d82SAndre Fischer 
MasterPageContainer(void)23702c50d82SAndre Fischer MasterPageContainer::MasterPageContainer (void)
23802c50d82SAndre Fischer     : mpImpl(Implementation::Instance()),
23902c50d82SAndre Fischer       mePreviewSize(SMALL)
24002c50d82SAndre Fischer {
24102c50d82SAndre Fischer     mpImpl->LateInit();
24202c50d82SAndre Fischer }
24302c50d82SAndre Fischer 
24402c50d82SAndre Fischer 
24502c50d82SAndre Fischer 
24602c50d82SAndre Fischer 
~MasterPageContainer(void)24702c50d82SAndre Fischer MasterPageContainer::~MasterPageContainer (void)
24802c50d82SAndre Fischer {
24902c50d82SAndre Fischer }
25002c50d82SAndre Fischer 
25102c50d82SAndre Fischer 
25202c50d82SAndre Fischer 
25302c50d82SAndre Fischer 
AddChangeListener(const Link & rLink)25402c50d82SAndre Fischer void MasterPageContainer::AddChangeListener (const Link& rLink)
25502c50d82SAndre Fischer {
25602c50d82SAndre Fischer     mpImpl->AddChangeListener(rLink);
25702c50d82SAndre Fischer }
25802c50d82SAndre Fischer 
25902c50d82SAndre Fischer 
26002c50d82SAndre Fischer 
26102c50d82SAndre Fischer 
RemoveChangeListener(const Link & rLink)26202c50d82SAndre Fischer void MasterPageContainer::RemoveChangeListener (const Link& rLink)
26302c50d82SAndre Fischer {
26402c50d82SAndre Fischer     mpImpl->RemoveChangeListener(rLink);
26502c50d82SAndre Fischer }
26602c50d82SAndre Fischer 
26702c50d82SAndre Fischer 
26802c50d82SAndre Fischer 
26902c50d82SAndre Fischer 
SetPreviewSize(PreviewSize eSize)27002c50d82SAndre Fischer void MasterPageContainer::SetPreviewSize (PreviewSize eSize)
27102c50d82SAndre Fischer {
27202c50d82SAndre Fischer     mePreviewSize = eSize;
27302c50d82SAndre Fischer     mpImpl->FireContainerChange(
27402c50d82SAndre Fischer         MasterPageContainerChangeEvent::SIZE_CHANGED,
27502c50d82SAndre Fischer         NIL_TOKEN);
27602c50d82SAndre Fischer }
27702c50d82SAndre Fischer 
27802c50d82SAndre Fischer 
27902c50d82SAndre Fischer 
28002c50d82SAndre Fischer 
GetPreviewSize(void) const28102c50d82SAndre Fischer MasterPageContainer::PreviewSize MasterPageContainer::GetPreviewSize (void) const
28202c50d82SAndre Fischer {
28302c50d82SAndre Fischer     return mePreviewSize;
28402c50d82SAndre Fischer }
28502c50d82SAndre Fischer 
28602c50d82SAndre Fischer 
28702c50d82SAndre Fischer 
28802c50d82SAndre Fischer 
GetPreviewSizePixel(void) const28902c50d82SAndre Fischer Size MasterPageContainer::GetPreviewSizePixel (void) const
29002c50d82SAndre Fischer {
29102c50d82SAndre Fischer     return mpImpl->GetPreviewSizePixel(mePreviewSize);
29202c50d82SAndre Fischer }
29302c50d82SAndre Fischer 
29402c50d82SAndre Fischer 
29502c50d82SAndre Fischer 
29602c50d82SAndre Fischer 
PutMasterPage(const SharedMasterPageDescriptor & rDescriptor)29702c50d82SAndre Fischer MasterPageContainer::Token MasterPageContainer::PutMasterPage (
29802c50d82SAndre Fischer     const SharedMasterPageDescriptor& rDescriptor)
29902c50d82SAndre Fischer {
30002c50d82SAndre Fischer     return mpImpl->PutMasterPage(rDescriptor);
30102c50d82SAndre Fischer }
30202c50d82SAndre Fischer 
30302c50d82SAndre Fischer 
30402c50d82SAndre Fischer 
30502c50d82SAndre Fischer 
AcquireToken(Token aToken)30602c50d82SAndre Fischer void MasterPageContainer::AcquireToken (Token aToken)
30702c50d82SAndre Fischer {
30802c50d82SAndre Fischer     SharedMasterPageDescriptor pDescriptor = mpImpl->GetDescriptor(aToken);
30902c50d82SAndre Fischer     if (pDescriptor.get() != NULL)
31002c50d82SAndre Fischer     {
31102c50d82SAndre Fischer         ++pDescriptor->mnUseCount;
31202c50d82SAndre Fischer     }
31302c50d82SAndre Fischer }
31402c50d82SAndre Fischer 
31502c50d82SAndre Fischer 
31602c50d82SAndre Fischer 
31702c50d82SAndre Fischer 
ReleaseToken(Token aToken)31802c50d82SAndre Fischer void MasterPageContainer::ReleaseToken (Token aToken)
31902c50d82SAndre Fischer {
32002c50d82SAndre Fischer     SharedMasterPageDescriptor pDescriptor = mpImpl->GetDescriptor(aToken);
32102c50d82SAndre Fischer     if (pDescriptor.get() != NULL)
32202c50d82SAndre Fischer     {
32302c50d82SAndre Fischer         OSL_ASSERT(pDescriptor->mnUseCount>0);
32402c50d82SAndre Fischer         --pDescriptor->mnUseCount;
32502c50d82SAndre Fischer         if (pDescriptor->mnUseCount <= 0)
32602c50d82SAndre Fischer         {
32702c50d82SAndre Fischer             switch (pDescriptor->meOrigin)
32802c50d82SAndre Fischer             {
32902c50d82SAndre Fischer                 case DEFAULT:
33002c50d82SAndre Fischer                 case TEMPLATE:
33102c50d82SAndre Fischer                 default:
33202c50d82SAndre Fischer                     break;
33302c50d82SAndre Fischer 
33402c50d82SAndre Fischer                 case MASTERPAGE:
33502c50d82SAndre Fischer                     mpImpl->ReleaseDescriptor(aToken);
33602c50d82SAndre Fischer                     break;
33702c50d82SAndre Fischer             }
33802c50d82SAndre Fischer         }
33902c50d82SAndre Fischer     }
34002c50d82SAndre Fischer }
34102c50d82SAndre Fischer 
34202c50d82SAndre Fischer 
34302c50d82SAndre Fischer 
34402c50d82SAndre Fischer 
GetTokenCount(void) const34502c50d82SAndre Fischer int MasterPageContainer::GetTokenCount (void) const
34602c50d82SAndre Fischer {
34702c50d82SAndre Fischer     const ::osl::MutexGuard aGuard (mpImpl->maMutex);
34802c50d82SAndre Fischer 
34902c50d82SAndre Fischer     return mpImpl->maContainer.size();
35002c50d82SAndre Fischer }
35102c50d82SAndre Fischer 
35202c50d82SAndre Fischer 
35302c50d82SAndre Fischer 
35402c50d82SAndre Fischer 
HasToken(Token aToken) const35502c50d82SAndre Fischer bool MasterPageContainer::HasToken (Token aToken) const
35602c50d82SAndre Fischer {
35702c50d82SAndre Fischer     const ::osl::MutexGuard aGuard (mpImpl->maMutex);
35802c50d82SAndre Fischer 
35902c50d82SAndre Fischer     return mpImpl->HasToken(aToken);
36002c50d82SAndre Fischer }
36102c50d82SAndre Fischer 
36202c50d82SAndre Fischer 
36302c50d82SAndre Fischer 
36402c50d82SAndre Fischer 
GetTokenForIndex(int nIndex)36502c50d82SAndre Fischer MasterPageContainer::Token MasterPageContainer::GetTokenForIndex (int nIndex)
36602c50d82SAndre Fischer {
36702c50d82SAndre Fischer     const ::osl::MutexGuard aGuard (mpImpl->maMutex);
36802c50d82SAndre Fischer 
36902c50d82SAndre Fischer     Token aResult (NIL_TOKEN);
37002c50d82SAndre Fischer     if (HasToken(nIndex))
37102c50d82SAndre Fischer         aResult = mpImpl->maContainer[nIndex]->maToken;
37202c50d82SAndre Fischer     return aResult;
37302c50d82SAndre Fischer }
37402c50d82SAndre Fischer 
37502c50d82SAndre Fischer 
37602c50d82SAndre Fischer 
37702c50d82SAndre Fischer 
GetTokenForURL(const String & sURL)37802c50d82SAndre Fischer MasterPageContainer::Token MasterPageContainer::GetTokenForURL (
37902c50d82SAndre Fischer     const String& sURL)
38002c50d82SAndre Fischer {
38102c50d82SAndre Fischer     const ::osl::MutexGuard aGuard (mpImpl->maMutex);
38202c50d82SAndre Fischer 
38302c50d82SAndre Fischer     Token aResult (NIL_TOKEN);
38402c50d82SAndre Fischer     if (sURL.Len() > 0)
38502c50d82SAndre Fischer     {
38602c50d82SAndre Fischer         MasterPageContainerType::iterator iEntry (
38702c50d82SAndre Fischer             ::std::find_if (
38802c50d82SAndre Fischer                 mpImpl->maContainer.begin(),
38902c50d82SAndre Fischer                 mpImpl->maContainer.end(),
39002c50d82SAndre Fischer                 MasterPageDescriptor::URLComparator(sURL)));
39102c50d82SAndre Fischer         if (iEntry != mpImpl->maContainer.end())
39202c50d82SAndre Fischer             aResult = (*iEntry)->maToken;
39302c50d82SAndre Fischer     }
39402c50d82SAndre Fischer     return aResult;
39502c50d82SAndre Fischer }
39602c50d82SAndre Fischer 
39702c50d82SAndre Fischer 
39802c50d82SAndre Fischer 
39902c50d82SAndre Fischer 
GetTokenForStyleName(const String & sStyleName)40002c50d82SAndre Fischer MasterPageContainer::Token MasterPageContainer::GetTokenForStyleName (const String& sStyleName)
40102c50d82SAndre Fischer {
40202c50d82SAndre Fischer     const ::osl::MutexGuard aGuard (mpImpl->maMutex);
40302c50d82SAndre Fischer 
40402c50d82SAndre Fischer     Token aResult (NIL_TOKEN);
40502c50d82SAndre Fischer     if (sStyleName.Len() > 0)
40602c50d82SAndre Fischer     {
40702c50d82SAndre Fischer         MasterPageContainerType::iterator iEntry (
40802c50d82SAndre Fischer             ::std::find_if (
40902c50d82SAndre Fischer                 mpImpl->maContainer.begin(),
41002c50d82SAndre Fischer                 mpImpl->maContainer.end(),
41102c50d82SAndre Fischer                 MasterPageDescriptor::StyleNameComparator(sStyleName)));
41202c50d82SAndre Fischer         if (iEntry != mpImpl->maContainer.end())
41302c50d82SAndre Fischer             aResult = (*iEntry)->maToken;
41402c50d82SAndre Fischer     }
41502c50d82SAndre Fischer     return aResult;
41602c50d82SAndre Fischer }
41702c50d82SAndre Fischer 
41802c50d82SAndre Fischer 
41902c50d82SAndre Fischer 
42002c50d82SAndre Fischer 
GetTokenForPageObject(const SdPage * pPage)42102c50d82SAndre Fischer MasterPageContainer::Token MasterPageContainer::GetTokenForPageObject (
42202c50d82SAndre Fischer     const SdPage* pPage)
42302c50d82SAndre Fischer {
42402c50d82SAndre Fischer     const ::osl::MutexGuard aGuard (mpImpl->maMutex);
42502c50d82SAndre Fischer 
42602c50d82SAndre Fischer     Token aResult (NIL_TOKEN);
42702c50d82SAndre Fischer     if (pPage != NULL)
42802c50d82SAndre Fischer     {
42902c50d82SAndre Fischer         MasterPageContainerType::iterator iEntry (
43002c50d82SAndre Fischer             ::std::find_if (
43102c50d82SAndre Fischer                 mpImpl->maContainer.begin(),
43202c50d82SAndre Fischer                 mpImpl->maContainer.end(),
43302c50d82SAndre Fischer                 MasterPageDescriptor::PageObjectComparator(pPage)));
43402c50d82SAndre Fischer         if (iEntry != mpImpl->maContainer.end())
43502c50d82SAndre Fischer             aResult = (*iEntry)->maToken;
43602c50d82SAndre Fischer     }
43702c50d82SAndre Fischer     return aResult;
43802c50d82SAndre Fischer }
43902c50d82SAndre Fischer 
44002c50d82SAndre Fischer 
44102c50d82SAndre Fischer 
44202c50d82SAndre Fischer 
GetURLForToken(MasterPageContainer::Token aToken)44302c50d82SAndre Fischer String MasterPageContainer::GetURLForToken (
44402c50d82SAndre Fischer     MasterPageContainer::Token aToken)
44502c50d82SAndre Fischer {
44602c50d82SAndre Fischer     const ::osl::MutexGuard aGuard (mpImpl->maMutex);
44702c50d82SAndre Fischer 
44802c50d82SAndre Fischer     SharedMasterPageDescriptor pDescriptor = mpImpl->GetDescriptor(aToken);
44902c50d82SAndre Fischer     if (pDescriptor.get() != NULL)
45002c50d82SAndre Fischer         return pDescriptor->msURL;
45102c50d82SAndre Fischer     else
45202c50d82SAndre Fischer         return String();
45302c50d82SAndre Fischer }
45402c50d82SAndre Fischer 
45502c50d82SAndre Fischer 
45602c50d82SAndre Fischer 
45702c50d82SAndre Fischer 
GetPageNameForToken(MasterPageContainer::Token aToken)45802c50d82SAndre Fischer String MasterPageContainer::GetPageNameForToken (
45902c50d82SAndre Fischer     MasterPageContainer::Token aToken)
46002c50d82SAndre Fischer {
46102c50d82SAndre Fischer     const ::osl::MutexGuard aGuard (mpImpl->maMutex);
46202c50d82SAndre Fischer 
46302c50d82SAndre Fischer     SharedMasterPageDescriptor pDescriptor = mpImpl->GetDescriptor(aToken);
46402c50d82SAndre Fischer     if (pDescriptor.get() != NULL)
46502c50d82SAndre Fischer         return pDescriptor->msPageName;
46602c50d82SAndre Fischer     else
46702c50d82SAndre Fischer         return String();
46802c50d82SAndre Fischer }
46902c50d82SAndre Fischer 
47002c50d82SAndre Fischer 
47102c50d82SAndre Fischer 
47202c50d82SAndre Fischer 
GetStyleNameForToken(MasterPageContainer::Token aToken)47302c50d82SAndre Fischer String MasterPageContainer::GetStyleNameForToken (
47402c50d82SAndre Fischer     MasterPageContainer::Token aToken)
47502c50d82SAndre Fischer {
47602c50d82SAndre Fischer     const ::osl::MutexGuard aGuard (mpImpl->maMutex);
47702c50d82SAndre Fischer 
47802c50d82SAndre Fischer     SharedMasterPageDescriptor pDescriptor = mpImpl->GetDescriptor(aToken);
47902c50d82SAndre Fischer     if (pDescriptor.get() != NULL)
48002c50d82SAndre Fischer         return pDescriptor->msStyleName;
48102c50d82SAndre Fischer     else
48202c50d82SAndre Fischer         return String();
48302c50d82SAndre Fischer }
48402c50d82SAndre Fischer 
48502c50d82SAndre Fischer 
48602c50d82SAndre Fischer 
48702c50d82SAndre Fischer 
GetPageObjectForToken(MasterPageContainer::Token aToken,bool bLoad)48802c50d82SAndre Fischer SdPage* MasterPageContainer::GetPageObjectForToken (
48902c50d82SAndre Fischer     MasterPageContainer::Token aToken,
49002c50d82SAndre Fischer     bool bLoad)
49102c50d82SAndre Fischer {
49202c50d82SAndre Fischer     const ::osl::MutexGuard aGuard (mpImpl->maMutex);
49302c50d82SAndre Fischer 
49402c50d82SAndre Fischer     SdPage* pPageObject = NULL;
49502c50d82SAndre Fischer     SharedMasterPageDescriptor pDescriptor = mpImpl->GetDescriptor(aToken);
49602c50d82SAndre Fischer     if (pDescriptor.get() != NULL)
49702c50d82SAndre Fischer     {
49802c50d82SAndre Fischer         pPageObject = pDescriptor->mpMasterPage;
49902c50d82SAndre Fischer         if (pPageObject == NULL)
50002c50d82SAndre Fischer         {
50102c50d82SAndre Fischer             // The page object is not (yet) present.  Call
50202c50d82SAndre Fischer             // UpdateDescriptor() to trigger the PageObjectProvider() to
50302c50d82SAndre Fischer             // provide it.
50402c50d82SAndre Fischer             if (bLoad)
50502c50d82SAndre Fischer                 mpImpl->GetModel();
50602c50d82SAndre Fischer             if (mpImpl->UpdateDescriptor(pDescriptor,bLoad,false, true))
50702c50d82SAndre Fischer                 pPageObject = pDescriptor->mpMasterPage;
50802c50d82SAndre Fischer         }
50902c50d82SAndre Fischer     }
51002c50d82SAndre Fischer     return pPageObject;
51102c50d82SAndre Fischer }
51202c50d82SAndre Fischer 
51302c50d82SAndre Fischer 
51402c50d82SAndre Fischer 
51502c50d82SAndre Fischer 
GetOriginForToken(Token aToken)51602c50d82SAndre Fischer MasterPageContainer::Origin MasterPageContainer::GetOriginForToken (Token aToken)
51702c50d82SAndre Fischer {
51802c50d82SAndre Fischer     const ::osl::MutexGuard aGuard (mpImpl->maMutex);
51902c50d82SAndre Fischer 
52002c50d82SAndre Fischer     SharedMasterPageDescriptor pDescriptor = mpImpl->GetDescriptor(aToken);
52102c50d82SAndre Fischer     if (pDescriptor.get() != NULL)
52202c50d82SAndre Fischer         return pDescriptor->meOrigin;
52302c50d82SAndre Fischer     else
52402c50d82SAndre Fischer         return UNKNOWN;
52502c50d82SAndre Fischer }
52602c50d82SAndre Fischer 
52702c50d82SAndre Fischer 
52802c50d82SAndre Fischer 
52902c50d82SAndre Fischer 
GetTemplateIndexForToken(Token aToken)53002c50d82SAndre Fischer sal_Int32 MasterPageContainer::GetTemplateIndexForToken (Token aToken)
53102c50d82SAndre Fischer {
53202c50d82SAndre Fischer     const ::osl::MutexGuard aGuard (mpImpl->maMutex);
53302c50d82SAndre Fischer 
53402c50d82SAndre Fischer     SharedMasterPageDescriptor pDescriptor = mpImpl->GetDescriptor(aToken);
53502c50d82SAndre Fischer     if (pDescriptor.get() != NULL)
53602c50d82SAndre Fischer         return pDescriptor->mnTemplateIndex;
53702c50d82SAndre Fischer     else
53802c50d82SAndre Fischer         return -1;
53902c50d82SAndre Fischer }
54002c50d82SAndre Fischer 
54102c50d82SAndre Fischer 
54202c50d82SAndre Fischer 
54302c50d82SAndre Fischer 
GetDescriptorForToken(MasterPageContainer::Token aToken)54402c50d82SAndre Fischer SharedMasterPageDescriptor MasterPageContainer::GetDescriptorForToken (
54502c50d82SAndre Fischer     MasterPageContainer::Token aToken)
54602c50d82SAndre Fischer {
54702c50d82SAndre Fischer     const ::osl::MutexGuard aGuard (mpImpl->maMutex);
54802c50d82SAndre Fischer 
54902c50d82SAndre Fischer     return mpImpl->GetDescriptor(aToken);
55002c50d82SAndre Fischer }
55102c50d82SAndre Fischer 
55202c50d82SAndre Fischer 
55302c50d82SAndre Fischer 
InvalidatePreview(MasterPageContainer::Token aToken)55402c50d82SAndre Fischer void MasterPageContainer::InvalidatePreview (MasterPageContainer::Token aToken)
55502c50d82SAndre Fischer {
55602c50d82SAndre Fischer     mpImpl->InvalidatePreview(aToken);
55702c50d82SAndre Fischer }
55802c50d82SAndre Fischer 
55902c50d82SAndre Fischer 
56002c50d82SAndre Fischer 
56102c50d82SAndre Fischer 
GetPreviewForToken(MasterPageContainer::Token aToken)56202c50d82SAndre Fischer Image MasterPageContainer::GetPreviewForToken (MasterPageContainer::Token aToken)
56302c50d82SAndre Fischer {
56402c50d82SAndre Fischer     return mpImpl->GetPreviewForToken(aToken,mePreviewSize);
56502c50d82SAndre Fischer }
56602c50d82SAndre Fischer 
56702c50d82SAndre Fischer 
56802c50d82SAndre Fischer 
56902c50d82SAndre Fischer 
GetPreviewState(Token aToken)57002c50d82SAndre Fischer MasterPageContainer::PreviewState MasterPageContainer::GetPreviewState (Token aToken)
57102c50d82SAndre Fischer {
57202c50d82SAndre Fischer     return mpImpl->GetPreviewState(aToken);
57302c50d82SAndre Fischer }
57402c50d82SAndre Fischer 
57502c50d82SAndre Fischer 
57602c50d82SAndre Fischer 
57702c50d82SAndre Fischer 
RequestPreview(Token aToken)57802c50d82SAndre Fischer bool MasterPageContainer::RequestPreview (Token aToken)
57902c50d82SAndre Fischer {
58002c50d82SAndre Fischer     return mpImpl->RequestPreview(aToken);
58102c50d82SAndre Fischer }
58202c50d82SAndre Fischer 
58302c50d82SAndre Fischer 
58402c50d82SAndre Fischer 
58502c50d82SAndre Fischer 
58602c50d82SAndre Fischer //==== Implementation ================================================
58702c50d82SAndre Fischer 
Implementation(void)58802c50d82SAndre Fischer MasterPageContainer::Implementation::Implementation (void)
58902c50d82SAndre Fischer     : maMutex(),
59002c50d82SAndre Fischer       maContainer(),
59102c50d82SAndre Fischer 	  meInitializationState(NOT_INITIALIZED),
59202c50d82SAndre Fischer       mpRequestQueue(NULL),
59302c50d82SAndre Fischer       mxModel(NULL),
59402c50d82SAndre Fischer       mpDocument(NULL),
59502c50d82SAndre Fischer       maPreviewRenderer(),
59602c50d82SAndre Fischer       mbFirstPageObjectSeen(false),
59702c50d82SAndre Fischer       maLargePreviewBeingCreated(),
59802c50d82SAndre Fischer       maSmallPreviewBeingCreated(),
59902c50d82SAndre Fischer       maLargePreviewNotAvailable(),
60002c50d82SAndre Fischer       maSmallPreviewNotAvailable(),
60102c50d82SAndre Fischer       maChangeListeners(),
60202c50d82SAndre Fischer       maSmallPreviewSizePixel(),
60302c50d82SAndre Fischer       maLargePreviewSizePixel(),
60402c50d82SAndre Fischer       mbPageRatioKnown(false),
60502c50d82SAndre Fischer       mbContainerCleaningPending(true)
60602c50d82SAndre Fischer 
60702c50d82SAndre Fischer {
60802c50d82SAndre Fischer     UpdatePreviewSizePixel();
60902c50d82SAndre Fischer }
61002c50d82SAndre Fischer 
61102c50d82SAndre Fischer 
61202c50d82SAndre Fischer 
61302c50d82SAndre Fischer 
~Implementation(void)61402c50d82SAndre Fischer MasterPageContainer::Implementation::~Implementation (void)
61502c50d82SAndre Fischer {
61602c50d82SAndre Fischer     // When the initializer or filler tasks are still running then we have
61702c50d82SAndre Fischer     // to stop them now in order to prevent them from calling us back.
61802c50d82SAndre Fischer     tools::TimerBasedTaskExecution::ReleaseTask(mpFillerTask);
61902c50d82SAndre Fischer 
62002c50d82SAndre Fischer     mpRequestQueue.reset();
62102c50d82SAndre Fischer 
62202c50d82SAndre Fischer     uno::Reference<util::XCloseable> xCloseable (mxModel, uno::UNO_QUERY);
62302c50d82SAndre Fischer     if (xCloseable.is())
62402c50d82SAndre Fischer     {
62502c50d82SAndre Fischer         try
62602c50d82SAndre Fischer         {
62702c50d82SAndre Fischer             xCloseable->close(true);
62802c50d82SAndre Fischer         }
62902c50d82SAndre Fischer         catch (::com::sun::star::util::CloseVetoException aException)
63002c50d82SAndre Fischer         {
63102c50d82SAndre Fischer         }
63202c50d82SAndre Fischer     }
63302c50d82SAndre Fischer     mxModel = NULL;
63402c50d82SAndre Fischer }
63502c50d82SAndre Fischer 
63602c50d82SAndre Fischer 
63702c50d82SAndre Fischer 
63802c50d82SAndre Fischer 
LateInit(void)63902c50d82SAndre Fischer void MasterPageContainer::Implementation::LateInit (void)
64002c50d82SAndre Fischer {
64102c50d82SAndre Fischer     const ::osl::MutexGuard aGuard (maMutex);
64202c50d82SAndre Fischer 
64302c50d82SAndre Fischer     if (meInitializationState == NOT_INITIALIZED)
64402c50d82SAndre Fischer     {
64502c50d82SAndre Fischer         meInitializationState = INITIALIZING;
64602c50d82SAndre Fischer 
64702c50d82SAndre Fischer         OSL_ASSERT(Instance().get()==this);
64802c50d82SAndre Fischer         mpRequestQueue.reset(MasterPageContainerQueue::Create(
64902c50d82SAndre Fischer             ::boost::shared_ptr<MasterPageContainerQueue::ContainerAdapter>(Instance())));
65002c50d82SAndre Fischer 
65102c50d82SAndre Fischer         mpFillerTask = ::sd::tools::TimerBasedTaskExecution::Create(
65202c50d82SAndre Fischer             ::boost::shared_ptr<tools::AsynchronousTask>(new MasterPageContainerFiller(*this)),
65302c50d82SAndre Fischer             5,
65402c50d82SAndre Fischer             50);
65502c50d82SAndre Fischer 
65602c50d82SAndre Fischer         meInitializationState = INITIALIZED;
65702c50d82SAndre Fischer     }
65802c50d82SAndre Fischer }
65902c50d82SAndre Fischer 
66002c50d82SAndre Fischer 
66102c50d82SAndre Fischer 
66202c50d82SAndre Fischer 
AddChangeListener(const Link & rLink)66302c50d82SAndre Fischer void MasterPageContainer::Implementation::AddChangeListener (const Link& rLink)
66402c50d82SAndre Fischer {
66502c50d82SAndre Fischer     const ::osl::MutexGuard aGuard (maMutex);
66602c50d82SAndre Fischer 
66702c50d82SAndre Fischer     ::std::vector<Link>::iterator iListener (
66802c50d82SAndre Fischer         ::std::find(maChangeListeners.begin(),maChangeListeners.end(),rLink));
66902c50d82SAndre Fischer     if (iListener == maChangeListeners.end())
67002c50d82SAndre Fischer         maChangeListeners.push_back(rLink);
67102c50d82SAndre Fischer 
67202c50d82SAndre Fischer }
67302c50d82SAndre Fischer 
67402c50d82SAndre Fischer 
67502c50d82SAndre Fischer 
67602c50d82SAndre Fischer 
RemoveChangeListener(const Link & rLink)67702c50d82SAndre Fischer void MasterPageContainer::Implementation::RemoveChangeListener (const Link& rLink)
67802c50d82SAndre Fischer {
67902c50d82SAndre Fischer     const ::osl::MutexGuard aGuard (maMutex);
68002c50d82SAndre Fischer 
68102c50d82SAndre Fischer     ::std::vector<Link>::iterator iListener (
68202c50d82SAndre Fischer         ::std::find(maChangeListeners.begin(),maChangeListeners.end(),rLink));
68302c50d82SAndre Fischer     if (iListener != maChangeListeners.end())
68402c50d82SAndre Fischer         maChangeListeners.erase(iListener);
68502c50d82SAndre Fischer }
68602c50d82SAndre Fischer 
68702c50d82SAndre Fischer 
68802c50d82SAndre Fischer 
68902c50d82SAndre Fischer 
UpdatePreviewSizePixel(void)69002c50d82SAndre Fischer void MasterPageContainer::Implementation::UpdatePreviewSizePixel (void)
69102c50d82SAndre Fischer {
69202c50d82SAndre Fischer     const ::osl::MutexGuard aGuard (maMutex);
69302c50d82SAndre Fischer 
69402c50d82SAndre Fischer     // The default aspect ratio is 4:3
69502c50d82SAndre Fischer     int nWidth (4);
69602c50d82SAndre Fischer     int nHeight (3);
69702c50d82SAndre Fischer 
69802c50d82SAndre Fischer     // Search for the first entry with an existing master page.
69902c50d82SAndre Fischer     MasterPageContainerType::const_iterator iDescriptor;
70002c50d82SAndre Fischer     MasterPageContainerType::const_iterator iContainerEnd(maContainer.end());
70102c50d82SAndre Fischer     for (iDescriptor=maContainer.begin(); iDescriptor!=iContainerEnd; ++iDescriptor)
702*b862c97cSHerbert Dürr         if( bool(*iDescriptor) && (*iDescriptor)->mpMasterPage != NULL)
70302c50d82SAndre Fischer         {
70402c50d82SAndre Fischer             Size aPageSize ((*iDescriptor)->mpMasterPage->GetSize());
70502c50d82SAndre Fischer             nWidth = aPageSize.Width();
70602c50d82SAndre Fischer             nHeight = aPageSize.Height();
70702c50d82SAndre Fischer             mbFirstPageObjectSeen = true;
70802c50d82SAndre Fischer             break;
70902c50d82SAndre Fischer         }
71002c50d82SAndre Fischer 
71102c50d82SAndre Fischer     maSmallPreviewSizePixel.Width() = SMALL_PREVIEW_WIDTH;
71202c50d82SAndre Fischer     maLargePreviewSizePixel.Width() = LARGE_PREVIEW_WIDTH;
71302c50d82SAndre Fischer 
71402c50d82SAndre Fischer     int nNewSmallHeight ((maSmallPreviewSizePixel.Width()-2) * nHeight / nWidth + 2);
71502c50d82SAndre Fischer     int nNewLargeHeight ((maLargePreviewSizePixel.Width()-2) * nHeight / nWidth + 2);
71602c50d82SAndre Fischer 
71702c50d82SAndre Fischer     if (nNewSmallHeight!=maSmallPreviewSizePixel.Height()
71802c50d82SAndre Fischer         || nNewLargeHeight!=maLargePreviewSizePixel.Height())
71902c50d82SAndre Fischer     {
72002c50d82SAndre Fischer         maSmallPreviewSizePixel.Height() = nNewSmallHeight;
72102c50d82SAndre Fischer         maLargePreviewSizePixel.Height() = nNewLargeHeight;
72202c50d82SAndre Fischer         FireContainerChange(
72302c50d82SAndre Fischer             MasterPageContainerChangeEvent::SIZE_CHANGED,
72402c50d82SAndre Fischer             NIL_TOKEN);
72502c50d82SAndre Fischer     }
72602c50d82SAndre Fischer }
72702c50d82SAndre Fischer 
72802c50d82SAndre Fischer 
72902c50d82SAndre Fischer 
73002c50d82SAndre Fischer 
GetPreviewSizePixel(PreviewSize eSize) const73102c50d82SAndre Fischer Size MasterPageContainer::Implementation::GetPreviewSizePixel (PreviewSize eSize) const
73202c50d82SAndre Fischer {
73302c50d82SAndre Fischer     if (eSize == SMALL)
73402c50d82SAndre Fischer         return maSmallPreviewSizePixel;
73502c50d82SAndre Fischer     else
73602c50d82SAndre Fischer         return maLargePreviewSizePixel;
73702c50d82SAndre Fischer }
73802c50d82SAndre Fischer 
73902c50d82SAndre Fischer 
74002c50d82SAndre Fischer 
74102c50d82SAndre Fischer 
IMPL_LINK(MasterPageContainer::Implementation,AsynchronousNotifyCallback,EventData *,pData)74202c50d82SAndre Fischer IMPL_LINK(MasterPageContainer::Implementation,AsynchronousNotifyCallback, EventData*, pData)
74302c50d82SAndre Fischer {
74402c50d82SAndre Fischer     const ::osl::MutexGuard aGuard (maMutex);
74502c50d82SAndre Fischer 
74602c50d82SAndre Fischer     if (pData != NULL)
74702c50d82SAndre Fischer     {
74802c50d82SAndre Fischer         FireContainerChange(pData->first, pData->second, false);
74902c50d82SAndre Fischer         delete pData;
75002c50d82SAndre Fischer     }
75102c50d82SAndre Fischer 
75202c50d82SAndre Fischer     return 0;
75302c50d82SAndre Fischer }
75402c50d82SAndre Fischer 
75502c50d82SAndre Fischer 
75602c50d82SAndre Fischer 
75702c50d82SAndre Fischer 
PutMasterPage(const SharedMasterPageDescriptor & rpDescriptor)75802c50d82SAndre Fischer MasterPageContainer::Token MasterPageContainer::Implementation::PutMasterPage (
75902c50d82SAndre Fischer     const SharedMasterPageDescriptor& rpDescriptor)
76002c50d82SAndre Fischer {
76102c50d82SAndre Fischer     const ::osl::MutexGuard aGuard (maMutex);
76202c50d82SAndre Fischer 
76302c50d82SAndre Fischer     Token aResult (NIL_TOKEN);
76402c50d82SAndre Fischer 
76502c50d82SAndre Fischer     // Get page object and preview when that is inexpensive.
76602c50d82SAndre Fischer     UpdateDescriptor(rpDescriptor,false,false, false);
76702c50d82SAndre Fischer 
76802c50d82SAndre Fischer     // Look up the new MasterPageDescriptor and either insert it or update
76902c50d82SAndre Fischer     // an already existing one.
77002c50d82SAndre Fischer     MasterPageContainerType::iterator aEntry (
77102c50d82SAndre Fischer         ::std::find_if (
77202c50d82SAndre Fischer             maContainer.begin(),
77302c50d82SAndre Fischer             maContainer.end(),
77402c50d82SAndre Fischer             MasterPageDescriptor::AllComparator(rpDescriptor)));
77502c50d82SAndre Fischer     if (aEntry == maContainer.end())
77602c50d82SAndre Fischer     {
77702c50d82SAndre Fischer         // Insert a new MasterPageDescriptor.
77802c50d82SAndre Fischer         bool bIgnore (rpDescriptor->mpPageObjectProvider.get()==NULL
77902c50d82SAndre Fischer             && rpDescriptor->msURL.getLength()==0);
78002c50d82SAndre Fischer 
78102c50d82SAndre Fischer         if ( ! bIgnore)
78202c50d82SAndre Fischer         {
78302c50d82SAndre Fischer             if (mbContainerCleaningPending)
78402c50d82SAndre Fischer                 CleanContainer();
78502c50d82SAndre Fischer 
78602c50d82SAndre Fischer             aResult = maContainer.size();
78702c50d82SAndre Fischer             rpDescriptor->SetToken(aResult);
78802c50d82SAndre Fischer 
78902c50d82SAndre Fischer             // Templates are precious, i.e. we lock them so that they will
79002c50d82SAndre Fischer             // not be destroyed when (temporarily) no one references them.
79102c50d82SAndre Fischer             // They will only be deleted when the container is destroyed.
79202c50d82SAndre Fischer             switch (rpDescriptor->meOrigin)
79302c50d82SAndre Fischer             {
79402c50d82SAndre Fischer                 case TEMPLATE:
79502c50d82SAndre Fischer                 case DEFAULT:
79602c50d82SAndre Fischer                     ++rpDescriptor->mnUseCount;
79702c50d82SAndre Fischer                     break;
79802c50d82SAndre Fischer 
79902c50d82SAndre Fischer                 default:
80002c50d82SAndre Fischer                     break;
80102c50d82SAndre Fischer             }
80202c50d82SAndre Fischer 
80302c50d82SAndre Fischer             maContainer.push_back(rpDescriptor);
80402c50d82SAndre Fischer             aEntry = maContainer.end()-1;
80502c50d82SAndre Fischer 
80602c50d82SAndre Fischer             FireContainerChange(MasterPageContainerChangeEvent::CHILD_ADDED,aResult);
80702c50d82SAndre Fischer         }
80802c50d82SAndre Fischer     }
80902c50d82SAndre Fischer     else
81002c50d82SAndre Fischer     {
81102c50d82SAndre Fischer         // Update an existing MasterPageDescriptor.
81202c50d82SAndre Fischer         aResult = (*aEntry)->maToken;
81302c50d82SAndre Fischer         ::std::auto_ptr<std::vector<MasterPageContainerChangeEvent::EventType> > pEventTypes(
81402c50d82SAndre Fischer             (*aEntry)->Update(*rpDescriptor));
81502c50d82SAndre Fischer         if (pEventTypes.get()!=NULL && pEventTypes->size()>0)
81602c50d82SAndre Fischer         {
81702c50d82SAndre Fischer             // One or more aspects of the descriptor have changed.  Send
81802c50d82SAndre Fischer             // appropriate events to the listeners.
81902c50d82SAndre Fischer             UpdateDescriptor(*aEntry,false,false, true);
82002c50d82SAndre Fischer 
82102c50d82SAndre Fischer             std::vector<MasterPageContainerChangeEvent::EventType>::const_iterator iEventType;
82202c50d82SAndre Fischer             for (iEventType=pEventTypes->begin(); iEventType!=pEventTypes->end(); ++iEventType)
82302c50d82SAndre Fischer             {
82402c50d82SAndre Fischer                 FireContainerChange(
82502c50d82SAndre Fischer                     *iEventType,
82602c50d82SAndre Fischer                     (*aEntry)->maToken,
82702c50d82SAndre Fischer                     false);
82802c50d82SAndre Fischer             }
82902c50d82SAndre Fischer         }
83002c50d82SAndre Fischer     }
83102c50d82SAndre Fischer 
83202c50d82SAndre Fischer     return aResult;
83302c50d82SAndre Fischer }
83402c50d82SAndre Fischer 
83502c50d82SAndre Fischer 
83602c50d82SAndre Fischer 
83702c50d82SAndre Fischer 
HasToken(Token aToken) const83802c50d82SAndre Fischer bool MasterPageContainer::Implementation::HasToken (Token aToken) const
83902c50d82SAndre Fischer {
84002c50d82SAndre Fischer     return aToken>=0
84102c50d82SAndre Fischer         && (unsigned)aToken<maContainer.size()
84202c50d82SAndre Fischer         && maContainer[aToken].get()!=NULL;
84302c50d82SAndre Fischer }
84402c50d82SAndre Fischer 
84502c50d82SAndre Fischer 
84602c50d82SAndre Fischer 
84702c50d82SAndre Fischer 
GetDescriptor(Token aToken) const84802c50d82SAndre Fischer const SharedMasterPageDescriptor MasterPageContainer::Implementation::GetDescriptor (
84902c50d82SAndre Fischer     Token aToken) const
85002c50d82SAndre Fischer {
85102c50d82SAndre Fischer     if (aToken>=0 && (unsigned)aToken<maContainer.size())
85202c50d82SAndre Fischer         return maContainer[aToken];
85302c50d82SAndre Fischer     else
85402c50d82SAndre Fischer         return SharedMasterPageDescriptor();
85502c50d82SAndre Fischer }
85602c50d82SAndre Fischer 
85702c50d82SAndre Fischer 
85802c50d82SAndre Fischer 
85902c50d82SAndre Fischer 
GetDescriptor(Token aToken)86002c50d82SAndre Fischer SharedMasterPageDescriptor MasterPageContainer::Implementation::GetDescriptor (Token aToken)
86102c50d82SAndre Fischer {
86202c50d82SAndre Fischer     if (aToken>=0 && (unsigned)aToken<maContainer.size())
86302c50d82SAndre Fischer         return maContainer[aToken];
86402c50d82SAndre Fischer     else
86502c50d82SAndre Fischer         return SharedMasterPageDescriptor();
86602c50d82SAndre Fischer }
86702c50d82SAndre Fischer 
86802c50d82SAndre Fischer 
86902c50d82SAndre Fischer 
87002c50d82SAndre Fischer 
InvalidatePreview(Token aToken)87102c50d82SAndre Fischer void MasterPageContainer::Implementation::InvalidatePreview (Token aToken)
87202c50d82SAndre Fischer {
87302c50d82SAndre Fischer     const ::osl::MutexGuard aGuard (maMutex);
87402c50d82SAndre Fischer 
87502c50d82SAndre Fischer     SharedMasterPageDescriptor pDescriptor (GetDescriptor(aToken));
87602c50d82SAndre Fischer     if (pDescriptor.get() != NULL)
87702c50d82SAndre Fischer     {
87802c50d82SAndre Fischer         pDescriptor->maSmallPreview = Image();
87902c50d82SAndre Fischer         pDescriptor->maLargePreview = Image();
88002c50d82SAndre Fischer         RequestPreview(aToken);
88102c50d82SAndre Fischer     }
88202c50d82SAndre Fischer }
88302c50d82SAndre Fischer 
88402c50d82SAndre Fischer 
88502c50d82SAndre Fischer 
88602c50d82SAndre Fischer 
GetPreviewForToken(MasterPageContainer::Token aToken,PreviewSize ePreviewSize)88702c50d82SAndre Fischer Image MasterPageContainer::Implementation::GetPreviewForToken (
88802c50d82SAndre Fischer     MasterPageContainer::Token aToken,
88902c50d82SAndre Fischer     PreviewSize ePreviewSize)
89002c50d82SAndre Fischer {
89102c50d82SAndre Fischer     const ::osl::MutexGuard aGuard (maMutex);
89202c50d82SAndre Fischer 
89302c50d82SAndre Fischer     Image aPreview;
89402c50d82SAndre Fischer     PreviewState ePreviewState (GetPreviewState(aToken));
89502c50d82SAndre Fischer 
89602c50d82SAndre Fischer     SharedMasterPageDescriptor pDescriptor = GetDescriptor(aToken);
89702c50d82SAndre Fischer 
89802c50d82SAndre Fischer     // When the preview is missing but inexpensively creatable then do that
89902c50d82SAndre Fischer     // now.
90002c50d82SAndre Fischer     if (pDescriptor.get()!=NULL)
90102c50d82SAndre Fischer     {
90202c50d82SAndre Fischer         if (ePreviewState == PS_CREATABLE)
90302c50d82SAndre Fischer             if (UpdateDescriptor(pDescriptor, false,false, true))
90402c50d82SAndre Fischer                 if (pDescriptor->maLargePreview.GetSizePixel().Width() != 0)
90502c50d82SAndre Fischer                     ePreviewState = PS_AVAILABLE;
90602c50d82SAndre Fischer 
90702c50d82SAndre Fischer         switch (ePreviewState)
90802c50d82SAndre Fischer         {
90902c50d82SAndre Fischer             case PS_AVAILABLE:
91002c50d82SAndre Fischer                 aPreview = pDescriptor->GetPreview(ePreviewSize);
91102c50d82SAndre Fischer                 break;
91202c50d82SAndre Fischer 
91302c50d82SAndre Fischer             case PS_PREPARING:
91402c50d82SAndre Fischer                 aPreview = GetPreviewSubstitution(
91502c50d82SAndre Fischer                     STR_TASKPANEL_PREPARING_PREVIEW_SUBSTITUTION,
91602c50d82SAndre Fischer                     ePreviewSize);
91702c50d82SAndre Fischer                 break;
91802c50d82SAndre Fischer 
91902c50d82SAndre Fischer             case PS_CREATABLE:
92002c50d82SAndre Fischer                 aPreview = GetPreviewSubstitution(
92102c50d82SAndre Fischer                     STR_TASKPANEL_PREPARING_PREVIEW_SUBSTITUTION,
92202c50d82SAndre Fischer                     ePreviewSize);
92302c50d82SAndre Fischer                 break;
92402c50d82SAndre Fischer 
92502c50d82SAndre Fischer             case PS_NOT_AVAILABLE:
92602c50d82SAndre Fischer                 aPreview = GetPreviewSubstitution(
92702c50d82SAndre Fischer                     STR_TASKPANEL_NOT_AVAILABLE_SUBSTITUTION,
92802c50d82SAndre Fischer                     ePreviewSize);
92902c50d82SAndre Fischer                 if (ePreviewSize == SMALL)
93002c50d82SAndre Fischer                     pDescriptor->maSmallPreview = aPreview;
93102c50d82SAndre Fischer                 else
93202c50d82SAndre Fischer                     pDescriptor->maLargePreview = aPreview;
93302c50d82SAndre Fischer                 break;
93402c50d82SAndre Fischer         }
93502c50d82SAndre Fischer     }
93602c50d82SAndre Fischer 
93702c50d82SAndre Fischer     return aPreview;
93802c50d82SAndre Fischer }
93902c50d82SAndre Fischer 
94002c50d82SAndre Fischer 
94102c50d82SAndre Fischer 
94202c50d82SAndre Fischer 
GetPreviewState(Token aToken) const94302c50d82SAndre Fischer MasterPageContainer::PreviewState MasterPageContainer::Implementation::GetPreviewState (
94402c50d82SAndre Fischer     Token aToken) const
94502c50d82SAndre Fischer {
94602c50d82SAndre Fischer     const ::osl::MutexGuard aGuard (maMutex);
94702c50d82SAndre Fischer 
94802c50d82SAndre Fischer     PreviewState eState (PS_NOT_AVAILABLE);
94902c50d82SAndre Fischer 
95002c50d82SAndre Fischer     SharedMasterPageDescriptor pDescriptor = GetDescriptor(aToken);
95102c50d82SAndre Fischer     if (pDescriptor.get() != NULL)
95202c50d82SAndre Fischer     {
95302c50d82SAndre Fischer         if (pDescriptor->maLargePreview.GetSizePixel().Width() != 0)
95402c50d82SAndre Fischer             eState = PS_AVAILABLE;
95502c50d82SAndre Fischer         else if (pDescriptor->mpPreviewProvider.get() != NULL)
95602c50d82SAndre Fischer         {
95702c50d82SAndre Fischer             // The preview does not exist but can be created.  When that is
95802c50d82SAndre Fischer             // not expensive then do it at once.
95902c50d82SAndre Fischer             if (mpRequestQueue->HasRequest(aToken))
96002c50d82SAndre Fischer                 eState = PS_PREPARING;
96102c50d82SAndre Fischer             else
96202c50d82SAndre Fischer                 eState = PS_CREATABLE;
96302c50d82SAndre Fischer         }
96402c50d82SAndre Fischer         else
96502c50d82SAndre Fischer             eState = PS_NOT_AVAILABLE;
96602c50d82SAndre Fischer     }
96702c50d82SAndre Fischer 
96802c50d82SAndre Fischer     return eState;
96902c50d82SAndre Fischer }
97002c50d82SAndre Fischer 
97102c50d82SAndre Fischer 
97202c50d82SAndre Fischer 
97302c50d82SAndre Fischer 
RequestPreview(Token aToken)97402c50d82SAndre Fischer bool MasterPageContainer::Implementation::RequestPreview (Token aToken)
97502c50d82SAndre Fischer {
97602c50d82SAndre Fischer     SharedMasterPageDescriptor pDescriptor = GetDescriptor(aToken);
97702c50d82SAndre Fischer     if (pDescriptor.get() != NULL)
97802c50d82SAndre Fischer         return mpRequestQueue->RequestPreview(pDescriptor);
97902c50d82SAndre Fischer     else
98002c50d82SAndre Fischer         return false;
98102c50d82SAndre Fischer }
98202c50d82SAndre Fischer 
98302c50d82SAndre Fischer 
98402c50d82SAndre Fischer 
98502c50d82SAndre Fischer 
GetModel(void)98602c50d82SAndre Fischer Reference<frame::XModel> MasterPageContainer::Implementation::GetModel (void)
98702c50d82SAndre Fischer {
98802c50d82SAndre Fischer     const ::osl::MutexGuard aGuard (maMutex);
98902c50d82SAndre Fischer 
99002c50d82SAndre Fischer     if ( ! mxModel.is())
99102c50d82SAndre Fischer     {
99202c50d82SAndre Fischer         // Get the desktop a s service factory.
99302c50d82SAndre Fischer         ::rtl::OUString sDesktopServiceName (
99402c50d82SAndre Fischer             RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop"));
99502c50d82SAndre Fischer         uno::Reference<frame::XComponentLoader> xDesktop (
99602c50d82SAndre Fischer             ::comphelper::getProcessServiceFactory()->createInstance(
99702c50d82SAndre Fischer                 sDesktopServiceName),
99802c50d82SAndre Fischer             uno::UNO_QUERY);
99902c50d82SAndre Fischer 
100002c50d82SAndre Fischer         // Create a new model.
100102c50d82SAndre Fischer         ::rtl::OUString sModelServiceName (
100202c50d82SAndre Fischer             RTL_CONSTASCII_USTRINGPARAM(
100302c50d82SAndre Fischer                 "com.sun.star.presentation.PresentationDocument"));
100402c50d82SAndre Fischer         mxModel = uno::Reference<frame::XModel>(
100502c50d82SAndre Fischer             ::comphelper::getProcessServiceFactory()->createInstance(
100602c50d82SAndre Fischer                 sModelServiceName),
100702c50d82SAndre Fischer             uno::UNO_QUERY);
100802c50d82SAndre Fischer 
100902c50d82SAndre Fischer         // Initialize the model.
101002c50d82SAndre Fischer         uno::Reference<frame::XLoadable> xLoadable (mxModel,uno::UNO_QUERY);
101102c50d82SAndre Fischer         if (xLoadable.is())
101202c50d82SAndre Fischer             xLoadable->initNew();
101302c50d82SAndre Fischer 
101402c50d82SAndre Fischer         // Use its tunnel to get a pointer to its core implementation.
101502c50d82SAndre Fischer         uno::Reference<lang::XUnoTunnel> xUnoTunnel (mxModel, uno::UNO_QUERY);
101602c50d82SAndre Fischer         if (xUnoTunnel.is())
101702c50d82SAndre Fischer         {
101802c50d82SAndre Fischer             mpDocument = reinterpret_cast<SdXImpressDocument*>(
101902c50d82SAndre Fischer                 xUnoTunnel->getSomething(
102002c50d82SAndre Fischer                     SdXImpressDocument::getUnoTunnelId()))->GetDoc();
102102c50d82SAndre Fischer         }
102202c50d82SAndre Fischer 
102302c50d82SAndre Fischer         // Create a default page.
102402c50d82SAndre Fischer         uno::Reference<drawing::XDrawPagesSupplier> xSlideSupplier (mxModel, uno::UNO_QUERY);
102502c50d82SAndre Fischer         if (xSlideSupplier.is())
102602c50d82SAndre Fischer         {
102702c50d82SAndre Fischer             uno::Reference<drawing::XDrawPages> xSlides (
102802c50d82SAndre Fischer                 xSlideSupplier->getDrawPages(), uno::UNO_QUERY);
102902c50d82SAndre Fischer             if (xSlides.is())
103002c50d82SAndre Fischer             {
103102c50d82SAndre Fischer                 sal_Int32 nIndex (0);
103202c50d82SAndre Fischer                 uno::Reference<drawing::XDrawPage> xNewPage (xSlides->insertNewByIndex(nIndex));
103302c50d82SAndre Fischer                 uno::Reference<beans::XPropertySet> xProperties(xNewPage, uno::UNO_QUERY);
103402c50d82SAndre Fischer                 if (xProperties.is())
103502c50d82SAndre Fischer                     xProperties->setPropertyValue(
103602c50d82SAndre Fischer                         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Layout")),
103702c50d82SAndre Fischer                         makeAny((sal_Int16)AUTOLAYOUT_TITLE));
103802c50d82SAndre Fischer             }
103902c50d82SAndre Fischer         }
104002c50d82SAndre Fischer     }
104102c50d82SAndre Fischer     return mxModel;
104202c50d82SAndre Fischer }
104302c50d82SAndre Fischer 
104402c50d82SAndre Fischer 
104502c50d82SAndre Fischer 
104602c50d82SAndre Fischer 
GetDocument(void)104702c50d82SAndre Fischer SdDrawDocument* MasterPageContainer::Implementation::GetDocument (void)
104802c50d82SAndre Fischer {
104902c50d82SAndre Fischer     GetModel();
105002c50d82SAndre Fischer     return mpDocument;
105102c50d82SAndre Fischer }
105202c50d82SAndre Fischer 
105302c50d82SAndre Fischer 
105402c50d82SAndre Fischer 
105502c50d82SAndre Fischer 
GetPreviewSubstitution(sal_uInt16 nId,PreviewSize ePreviewSize)105602c50d82SAndre Fischer Image MasterPageContainer::Implementation::GetPreviewSubstitution (
105702c50d82SAndre Fischer     sal_uInt16 nId,
105802c50d82SAndre Fischer     PreviewSize ePreviewSize)
105902c50d82SAndre Fischer {
106002c50d82SAndre Fischer     const ::osl::MutexGuard aGuard (maMutex);
106102c50d82SAndre Fischer 
106202c50d82SAndre Fischer     Image aPreview;
106302c50d82SAndre Fischer 
106402c50d82SAndre Fischer     switch (nId)
106502c50d82SAndre Fischer     {
106602c50d82SAndre Fischer         case STR_TASKPANEL_PREPARING_PREVIEW_SUBSTITUTION:
106702c50d82SAndre Fischer         {
106802c50d82SAndre Fischer             Image& rPreview (ePreviewSize==SMALL
106902c50d82SAndre Fischer                 ? maSmallPreviewBeingCreated
107002c50d82SAndre Fischer                 : maLargePreviewBeingCreated);
107102c50d82SAndre Fischer             if (rPreview.GetSizePixel().Width() == 0)
107202c50d82SAndre Fischer             {
107302c50d82SAndre Fischer                 rPreview = maPreviewRenderer.RenderSubstitution(
107402c50d82SAndre Fischer                     ePreviewSize==SMALL ? maSmallPreviewSizePixel : maLargePreviewSizePixel,
107502c50d82SAndre Fischer                     SdResId(STR_TASKPANEL_PREPARING_PREVIEW_SUBSTITUTION));
107602c50d82SAndre Fischer             }
107702c50d82SAndre Fischer             aPreview = rPreview;
107802c50d82SAndre Fischer         }
107902c50d82SAndre Fischer         break;
108002c50d82SAndre Fischer 
108102c50d82SAndre Fischer         case STR_TASKPANEL_NOT_AVAILABLE_SUBSTITUTION:
108202c50d82SAndre Fischer         {
108302c50d82SAndre Fischer             Image& rPreview (ePreviewSize==SMALL
108402c50d82SAndre Fischer                 ? maSmallPreviewNotAvailable
108502c50d82SAndre Fischer                 : maLargePreviewNotAvailable);
108602c50d82SAndre Fischer             if (rPreview.GetSizePixel().Width() == 0)
108702c50d82SAndre Fischer             {
108802c50d82SAndre Fischer                 rPreview = maPreviewRenderer.RenderSubstitution(
108902c50d82SAndre Fischer                     ePreviewSize==SMALL ? maSmallPreviewSizePixel : maLargePreviewSizePixel,
109002c50d82SAndre Fischer                     SdResId(STR_TASKPANEL_NOT_AVAILABLE_SUBSTITUTION));
109102c50d82SAndre Fischer             }
109202c50d82SAndre Fischer             aPreview = rPreview;
109302c50d82SAndre Fischer         }
109402c50d82SAndre Fischer         break;
109502c50d82SAndre Fischer     }
109602c50d82SAndre Fischer 
109702c50d82SAndre Fischer     return aPreview;
109802c50d82SAndre Fischer }
109902c50d82SAndre Fischer 
110002c50d82SAndre Fischer 
110102c50d82SAndre Fischer 
110202c50d82SAndre Fischer 
CleanContainer(void)110302c50d82SAndre Fischer void MasterPageContainer::Implementation::CleanContainer (void)
110402c50d82SAndre Fischer {
110502c50d82SAndre Fischer     // Remove the empty elements at the end of the container.  The empty
110602c50d82SAndre Fischer     // elements in the middle can not be removed because that would
110702c50d82SAndre Fischer     // invalidate the references still held by others.
110802c50d82SAndre Fischer     int nIndex (maContainer.size()-1);
110902c50d82SAndre Fischer     while (nIndex>=0 && maContainer[nIndex].get()==NULL)
111002c50d82SAndre Fischer         --nIndex;
111102c50d82SAndre Fischer     maContainer.resize(++nIndex);
111202c50d82SAndre Fischer }
111302c50d82SAndre Fischer 
111402c50d82SAndre Fischer 
111502c50d82SAndre Fischer 
111602c50d82SAndre Fischer 
FireContainerChange(MasterPageContainerChangeEvent::EventType eType,Token aToken,bool bNotifyAsynchronously)111702c50d82SAndre Fischer void MasterPageContainer::Implementation::FireContainerChange (
111802c50d82SAndre Fischer     MasterPageContainerChangeEvent::EventType eType,
111902c50d82SAndre Fischer     Token aToken,
112002c50d82SAndre Fischer     bool bNotifyAsynchronously)
112102c50d82SAndre Fischer {
112202c50d82SAndre Fischer     if (bNotifyAsynchronously)
112302c50d82SAndre Fischer     {
112402c50d82SAndre Fischer         Application::PostUserEvent(
112502c50d82SAndre Fischer             LINK(this,Implementation,AsynchronousNotifyCallback),
112602c50d82SAndre Fischer             new EventData(eType,aToken));
112702c50d82SAndre Fischer     }
112802c50d82SAndre Fischer     else
112902c50d82SAndre Fischer     {
113002c50d82SAndre Fischer         ::std::vector<Link> aCopy(maChangeListeners.begin(),maChangeListeners.end());
113102c50d82SAndre Fischer         ::std::vector<Link>::iterator iListener;
113202c50d82SAndre Fischer         MasterPageContainerChangeEvent aEvent;
113302c50d82SAndre Fischer         aEvent.meEventType = eType;
113402c50d82SAndre Fischer         aEvent.maChildToken = aToken;
113502c50d82SAndre Fischer         for (iListener=aCopy.begin(); iListener!=aCopy.end(); ++iListener)
113602c50d82SAndre Fischer             iListener->Call(&aEvent);
113702c50d82SAndre Fischer     }
113802c50d82SAndre Fischer }
113902c50d82SAndre Fischer 
114002c50d82SAndre Fischer 
114102c50d82SAndre Fischer 
114202c50d82SAndre Fischer 
UpdateDescriptor(const SharedMasterPageDescriptor & rpDescriptor,bool bForcePageObject,bool bForcePreview,bool bSendEvents)114302c50d82SAndre Fischer bool MasterPageContainer::Implementation::UpdateDescriptor (
114402c50d82SAndre Fischer     const SharedMasterPageDescriptor& rpDescriptor,
114502c50d82SAndre Fischer     bool bForcePageObject,
114602c50d82SAndre Fischer     bool bForcePreview,
114702c50d82SAndre Fischer     bool bSendEvents)
114802c50d82SAndre Fischer {
114902c50d82SAndre Fischer     const ::osl::MutexGuard aGuard (maMutex);
115002c50d82SAndre Fischer 
115102c50d82SAndre Fischer     // We have to create the page object when the preview provider needs it
115202c50d82SAndre Fischer     // and the caller needs the preview.
115302c50d82SAndre Fischer     bForcePageObject |= (bForcePreview
115402c50d82SAndre Fischer         && rpDescriptor->mpPreviewProvider->NeedsPageObject()
115502c50d82SAndre Fischer         && rpDescriptor->mpMasterPage==NULL);
115602c50d82SAndre Fischer 
115702c50d82SAndre Fischer     // Define a cost threshold so that an update or page object or preview
115802c50d82SAndre Fischer     // that is at least this cost are made at once. Updates with higher cost
115902c50d82SAndre Fischer     // are scheduled for later.
116002c50d82SAndre Fischer     sal_Int32 nCostThreshold (mpRequestQueue->IsEmpty() ? 5 : 0);
116102c50d82SAndre Fischer 
116202c50d82SAndre Fischer     // Update the page object (which may be used for the preview update).
116302c50d82SAndre Fischer     if (bForcePageObject)
116402c50d82SAndre Fischer         GetDocument();
116502c50d82SAndre Fischer     bool bPageObjectModified (rpDescriptor->UpdatePageObject(
116602c50d82SAndre Fischer         (bForcePageObject ? -1 : nCostThreshold),
116702c50d82SAndre Fischer         mpDocument));
116802c50d82SAndre Fischer     if (bPageObjectModified && bSendEvents)
116902c50d82SAndre Fischer         FireContainerChange(
117002c50d82SAndre Fischer             MasterPageContainerChangeEvent::DATA_CHANGED,
117102c50d82SAndre Fischer             rpDescriptor->maToken);
117202c50d82SAndre Fischer     if (bPageObjectModified && ! mbFirstPageObjectSeen)
117302c50d82SAndre Fischer         UpdatePreviewSizePixel();
117402c50d82SAndre Fischer 
117502c50d82SAndre Fischer     // Update the preview.
117602c50d82SAndre Fischer     bool bPreviewModified (rpDescriptor->UpdatePreview(
117702c50d82SAndre Fischer         (bForcePreview ? -1 : nCostThreshold),
117802c50d82SAndre Fischer         maSmallPreviewSizePixel,
117902c50d82SAndre Fischer         maLargePreviewSizePixel,
118002c50d82SAndre Fischer         maPreviewRenderer));
118102c50d82SAndre Fischer 
118202c50d82SAndre Fischer     if (bPreviewModified && bSendEvents)
118302c50d82SAndre Fischer         FireContainerChange(
118402c50d82SAndre Fischer             MasterPageContainerChangeEvent::PREVIEW_CHANGED,
118502c50d82SAndre Fischer             rpDescriptor->maToken);
118602c50d82SAndre Fischer 
118702c50d82SAndre Fischer     return bPageObjectModified || bPreviewModified;
118802c50d82SAndre Fischer }
118902c50d82SAndre Fischer 
119002c50d82SAndre Fischer 
119102c50d82SAndre Fischer 
119202c50d82SAndre Fischer 
ReleaseDescriptor(Token aToken)119302c50d82SAndre Fischer void MasterPageContainer::Implementation::ReleaseDescriptor (Token aToken)
119402c50d82SAndre Fischer {
119502c50d82SAndre Fischer     if (aToken>=0 && (unsigned)aToken<maContainer.size())
119602c50d82SAndre Fischer     {
119702c50d82SAndre Fischer         maContainer[aToken].reset();
119802c50d82SAndre Fischer         mbContainerCleaningPending = true;
119902c50d82SAndre Fischer     }
120002c50d82SAndre Fischer }
120102c50d82SAndre Fischer 
120202c50d82SAndre Fischer 
120302c50d82SAndre Fischer 
120402c50d82SAndre Fischer 
FillingDone(void)120502c50d82SAndre Fischer void MasterPageContainer::Implementation::FillingDone (void)
120602c50d82SAndre Fischer {
120702c50d82SAndre Fischer     mpRequestQueue->ProcessAllRequests();
120802c50d82SAndre Fischer }
120902c50d82SAndre Fischer 
121002c50d82SAndre Fischer 
121102c50d82SAndre Fischer 
121202c50d82SAndre Fischer } } // end of namespace sd::sidebar
1213