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