32#include <unomodel.hxx>
33#include <com/sun/star/lang/XMultiServiceFactory.hpp>
34#include <com/sun/star/uno/Reference.hxx>
35#include <com/sun/star/uno/Any.hxx>
36#include <com/sun/star/util/XCloseable.hpp>
37#include <com/sun/star/util/CloseVetoException.hpp>
44#include <osl/mutex.hxx>
45#include <osl/getglobalmutex.hxx>
48#include <osl/diagnose.h>
55typedef ::std::vector<sd::sidebar::SharedMasterPageDescriptor> MasterPageContainerType;
74 static std::shared_ptr<Implementation>
Instance();
101 bool bForcePageObject,
103 bool bSendEvents)
override;
125 css::uno::Reference<css::frame::XModel>
mxModel;
167std::weak_ptr<MasterPageContainer::Implementation>
170std::shared_ptr<MasterPageContainer::Implementation>
173 std::shared_ptr<MasterPageContainer::Implementation> pInstance;
177 ::osl::GetGlobalMutex aMutexFunctor;
178 ::osl::MutexGuard aGuard (aMutexFunctor());
181 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
182 pInstance = std::shared_ptr<MasterPageContainer::Implementation>(
189 pInstance = std::shared_ptr<MasterPageContainer::Implementation>(
194 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
195 pInstance = std::shared_ptr<MasterPageContainer::Implementation>(
200 "MasterPageContainer::Implementation::Instance(): instance is nullptr");
217 mpImpl->AddChangeListener(rLink);
222 mpImpl->RemoveChangeListener(rLink);
228 mpImpl->FireContainerChange(
239 const std::shared_ptr<MasterPageDescriptor>& rDescriptor)
241 return mpImpl->PutMasterPage(rDescriptor);
249 ++pDescriptor->mnUseCount;
259 OSL_ASSERT(pDescriptor->mnUseCount>0);
260 --pDescriptor->mnUseCount;
261 if (pDescriptor->mnUseCount > 0)
264 switch (pDescriptor->meOrigin)
272 mpImpl->ReleaseDescriptor(aToken);
279 const ::osl::MutexGuard aGuard (
mpImpl->maMutex);
281 return mpImpl->maContainer.size();
286 const ::osl::MutexGuard aGuard (
mpImpl->maMutex);
288 return mpImpl->HasToken(aToken);
293 const ::osl::MutexGuard aGuard (
mpImpl->maMutex);
302 const OUString& sURL)
304 const ::osl::MutexGuard aGuard (
mpImpl->maMutex);
309 MasterPageContainerType::iterator iEntry (
311 mpImpl->maContainer.begin(),
312 mpImpl->maContainer.end(),
314 if (iEntry !=
mpImpl->maContainer.end())
315 aResult = (*iEntry)->maToken;
322 const ::osl::MutexGuard aGuard (
mpImpl->maMutex);
325 if (!sStyleName.isEmpty())
327 MasterPageContainerType::iterator iEntry (
329 mpImpl->maContainer.begin(),
330 mpImpl->maContainer.end(),
332 if (iEntry !=
mpImpl->maContainer.end())
333 aResult = (*iEntry)->maToken;
341 const ::osl::MutexGuard aGuard (
mpImpl->maMutex);
344 if (pPage !=
nullptr)
346 MasterPageContainerType::iterator iEntry (
348 mpImpl->maContainer.begin(),
349 mpImpl->maContainer.end(),
351 if (iEntry !=
mpImpl->maContainer.end())
352 aResult = (*iEntry)->maToken;
360 const ::osl::MutexGuard aGuard (
mpImpl->maMutex);
364 return pDescriptor->msURL;
372 const ::osl::MutexGuard aGuard (
mpImpl->maMutex);
376 return pDescriptor->msPageName;
384 const ::osl::MutexGuard aGuard (
mpImpl->maMutex);
388 return pDescriptor->msStyleName;
397 const ::osl::MutexGuard aGuard (
mpImpl->maMutex);
399 SdPage* pPageObject =
nullptr;
403 pPageObject = pDescriptor->mpMasterPage;
404 if (pPageObject ==
nullptr)
411 if (
mpImpl->UpdateDescriptor(pDescriptor,bLoad,
false,
true))
412 pPageObject = pDescriptor->mpMasterPage;
420 const ::osl::MutexGuard aGuard (
mpImpl->maMutex);
424 return pDescriptor->meOrigin;
431 const ::osl::MutexGuard aGuard (
mpImpl->maMutex);
435 return pDescriptor->mnTemplateIndex;
443 const ::osl::MutexGuard aGuard (
mpImpl->maMutex);
445 return mpImpl->GetDescriptor(aToken);
450 mpImpl->InvalidatePreview(aToken);
460 return mpImpl->GetPreviewState(aToken);
465 return mpImpl->RequestPreview(aToken);
473 mbFirstPageObjectSeen(false)
484 mpRequestQueue.reset();
486 uno::Reference<util::XCloseable> xCloseable (
mxModel, uno::UNO_QUERY);
491 xCloseable->close(
true);
493 catch (
const css::util::CloseVetoException&)
502 const ::osl::MutexGuard aGuard (
maMutex);
504 if (meInitializationState != InitializationState::NotInitialized)
507 meInitializationState = InitializationState::Initializing;
509 OSL_ASSERT(Instance().
get()==
this);
511 std::shared_ptr<MasterPageContainerQueue::ContainerAdapter>(Instance())));
514 std::make_shared<MasterPageContainerFiller>(*
this),
518 meInitializationState = InitializationState::Initialized;
523 const ::osl::MutexGuard aGuard (
maMutex);
525 ::std::vector<Link<MasterPageContainerChangeEvent&,void>>::iterator iListener (
526 ::std::find(maChangeListeners.begin(),maChangeListeners.end(),rLink));
527 if (iListener == maChangeListeners.end())
528 maChangeListeners.push_back(rLink);
534 const ::osl::MutexGuard aGuard (
maMutex);
536 ::std::vector<Link<MasterPageContainerChangeEvent&,void>>::iterator iListener (
537 ::std::find(maChangeListeners.begin(),maChangeListeners.end(),rLink));
538 if (iListener != maChangeListeners.end())
539 maChangeListeners.erase(iListener);
544 const ::osl::MutexGuard aGuard (
maMutex);
551 auto iDescriptor = std::find_if(maContainer.begin(), maContainer.end(),
553 return rxDescriptor != nullptr && rxDescriptor->mpMasterPage != nullptr;
555 if (iDescriptor != maContainer.end())
557 Size aPageSize ((*iDescriptor)->mpMasterPage->GetSize());
558 OSL_ASSERT(!aPageSize.
IsEmpty());
559 if (aPageSize.
Width() > 0)
560 nWidth = aPageSize.
Width();
561 if (aPageSize.
Height() > 0)
562 nHeight = aPageSize.
Height();
563 mbFirstPageObjectSeen =
true;
566 maSmallPreviewSizePixel.setWidth( SMALL_PREVIEW_WIDTH );
567 maLargePreviewSizePixel.setWidth( LARGE_PREVIEW_WIDTH );
569 int nNewSmallHeight ((maSmallPreviewSizePixel.Width()-2) * nHeight / nWidth + 2);
570 int nNewLargeHeight ((maLargePreviewSizePixel.Width()-2) * nHeight / nWidth + 2);
572 if (nNewSmallHeight!=maSmallPreviewSizePixel.Height()
573 || nNewLargeHeight!=maLargePreviewSizePixel.Height())
575 maSmallPreviewSizePixel.setHeight( nNewSmallHeight );
576 maLargePreviewSizePixel.setHeight( nNewLargeHeight );
586 return maSmallPreviewSizePixel;
588 return maLargePreviewSizePixel;
594 const ::osl::MutexGuard aGuard (
maMutex);
599 UpdateDescriptor(rpDescriptor,
false,
false,
false);
603 MasterPageContainerType::iterator aEntry (
608 if (aEntry == maContainer.end())
611 bool bIgnore(rpDescriptor->mpPageObjectProvider ==
nullptr
612 && rpDescriptor->msURL.isEmpty());
618 aResult = maContainer.size();
619 rpDescriptor->SetToken(aResult);
624 switch (rpDescriptor->meOrigin)
628 ++rpDescriptor->mnUseCount;
635 maContainer.push_back(rpDescriptor);
636 aEntry = maContainer.end()-1;
644 aResult = (*aEntry)->maToken;
645 std::unique_ptr<std::vector<MasterPageContainerChangeEvent::EventType> > pEventTypes(
646 (*aEntry)->Update(*rpDescriptor));
647 if (pEventTypes !=
nullptr && !pEventTypes->empty())
651 UpdateDescriptor(*aEntry,
false,
false,
true);
653 for (
const auto& rEventType : *pEventTypes)
655 FireContainerChange(rEventType, (*aEntry)->maToken);
667 && maContainer[aToken];
673 return maContainer[aToken];
680 const ::osl::MutexGuard aGuard (
maMutex);
685 pDescriptor->maSmallPreview =
Image();
686 pDescriptor->maLargePreview =
Image();
695 const ::osl::MutexGuard aGuard (
maMutex);
707 if (UpdateDescriptor(pDescriptor,
false,
false,
true))
708 if (pDescriptor->maLargePreview.GetSizePixel().Width() != 0)
711 switch (ePreviewState)
714 aPreview = pDescriptor->GetPreview(ePreviewSize);
718 aPreview = GetPreviewSubstitution(
719 STR_TASKPANEL_PREPARING_PREVIEW_SUBSTITUTION,
724 aPreview = GetPreviewSubstitution(
725 STR_TASKPANEL_PREPARING_PREVIEW_SUBSTITUTION,
730 aPreview = GetPreviewSubstitution(
731 STR_TASKPANEL_NOT_AVAILABLE_SUBSTITUTION,
733 if (ePreviewSize ==
SMALL)
734 pDescriptor->maSmallPreview = aPreview;
736 pDescriptor->maLargePreview = aPreview;
747 const ::osl::MutexGuard aGuard (
maMutex);
754 if (pDescriptor->maLargePreview.GetSizePixel().Width() != 0)
756 else if (pDescriptor->mpPreviewProvider !=
nullptr)
760 if (mpRequestQueue->HasRequest(aToken))
776 return mpRequestQueue->RequestPreview(pDescriptor);
783 const ::osl::MutexGuard aGuard (
maMutex);
790 "com.sun.star.presentation.PresentationDocument"),
794 uno::Reference<frame::XLoadable> xLoadable (
mxModel,uno::UNO_QUERY);
796 xLoadable->initNew();
799 uno::Reference<lang::XUnoTunnel> xUnoTunnel (
mxModel, uno::UNO_QUERY);
800 if (
auto pSdXImpressDocument = comphelper::getFromUnoTunnel<SdXImpressDocument>(xUnoTunnel))
802 mpDocument = pSdXImpressDocument->GetDoc();
806 uno::Reference<drawing::XDrawPagesSupplier> xSlideSupplier (
mxModel, uno::UNO_QUERY);
807 if (xSlideSupplier.is())
809 uno::Reference<drawing::XDrawPages> xSlides =
810 xSlideSupplier->getDrawPages();
813 uno::Reference<drawing::XDrawPage> xNewPage (xSlides->insertNewByIndex(0));
814 uno::Reference<beans::XPropertySet> xProperties(xNewPage, uno::UNO_QUERY);
815 if (xProperties.is())
816 xProperties->setPropertyValue(
835 const ::osl::MutexGuard aGuard (
maMutex);
839 if (pId == STR_TASKPANEL_PREPARING_PREVIEW_SUBSTITUTION)
842 ? maSmallPreviewBeingCreated
843 : maLargePreviewBeingCreated);
846 rPreview = maPreviewRenderer.RenderSubstitution(
847 ePreviewSize==
SMALL ? maSmallPreviewSizePixel : maLargePreviewSizePixel,
848 SdResId(STR_TASKPANEL_PREPARING_PREVIEW_SUBSTITUTION));
852 else if (pId == STR_TASKPANEL_NOT_AVAILABLE_SUBSTITUTION)
855 ? maSmallPreviewNotAvailable
856 : maLargePreviewNotAvailable);
859 rPreview = maPreviewRenderer.RenderSubstitution(
860 ePreviewSize==
SMALL ? maSmallPreviewSizePixel : maLargePreviewSizePixel,
861 SdResId(STR_TASKPANEL_NOT_AVAILABLE_SUBSTITUTION));
874 int nIndex (maContainer.size()-1);
877 maContainer.resize(++
nIndex);
884 ::std::vector<Link<MasterPageContainerChangeEvent&,void>> aCopy(maChangeListeners);
887 aEvent.maChildToken = aToken;
888 for (
const auto& rListener : aCopy)
894 bool bForcePageObject,
898 const ::osl::MutexGuard aGuard (
maMutex);
902 bForcePageObject |= (bForcePreview
903 && rpDescriptor->mpPreviewProvider->NeedsPageObject()
904 && rpDescriptor->mpMasterPage==
nullptr);
909 sal_Int32 nCostThreshold (mpRequestQueue->IsEmpty() ? 5 : 0);
912 if (bForcePageObject)
914 int nPageObjectModified (rpDescriptor->UpdatePageObject(
915 (bForcePageObject ? -1 : nCostThreshold),
917 if (nPageObjectModified == 1 && bSendEvents)
920 rpDescriptor->maToken);
921 if (nPageObjectModified == -1 && bSendEvents)
924 rpDescriptor->maToken);
925 if (nPageObjectModified && ! mbFirstPageObjectSeen)
926 UpdatePreviewSizePixel();
929 bool bPreviewModified (rpDescriptor->UpdatePreview(
930 (bForcePreview ? -1 : nCostThreshold),
931 maSmallPreviewSizePixel,
932 maLargePreviewSizePixel,
935 if (bPreviewModified && bSendEvents)
938 rpDescriptor->maToken);
940 return nPageObjectModified || bPreviewModified;
947 maContainer[aToken].reset();
953 mpRequestQueue->ProcessAllRequests();
css::uno::Reference< css::frame::XModel2 > mxModel
HRESULT createInstance(REFIID iid, Ifc **ppIfc)
Size GetSizePixel() const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
void AddResource(::std::unique_ptr< SdGlobalResource > pResource)
Add a resource to the container.
static SdGlobalResourceContainer & Instance()
#define DBG_ASSERT(sCon, aError)
EmbeddedObjectRef * pObject
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
OUString SdResId(TranslateId aId)