31#include <com/sun/star/drawing/framework/XControllerManager.hpp>
32#include <com/sun/star/frame/XController.hpp>
36#include <rtl/ustrbuf.hxx>
44#include <unordered_map>
55 css::drawing::framework::XConfigurationChangeListener
56 > CallbackCallerInterfaceBase;
65 :
public CallbackCallerInterfaceBase
87 const ::sd::ViewShellBase& rBase,
92 virtual void disposing(std::unique_lock<std::mutex>&)
override;
94 virtual void SAL_CALL disposing (
const lang::EventObject& rEvent)
override;
96 virtual void SAL_CALL notifyConfigurationChange (
const ConfigurationChangeEvent& rEvent)
override;
100 Reference<XConfigurationController> mxConfigurationController;
108 css::lang::XEventListener
109 > LifetimeControllerInterfaceBase;
116class LifetimeController
117 :
public LifetimeControllerInterfaceBase,
122 virtual ~LifetimeController()
override;
127 using WeakComponentImplHelperBase::disposing;
128 virtual void SAL_CALL disposing (
const lang::EventObject& rEvent)
override;
136 bool mbListeningToViewShellBase;
137 bool mbListeningToController;
152 class FrameworkHelperAllPassFilter
155 bool operator() (
const css::drawing::framework::ConfigurationChangeEvent&) {
return true; }
158 class FrameworkHelperResourceIdFilter
161 explicit FrameworkHelperResourceIdFilter (
162 const css::uno::Reference<css::drawing::framework::XResourceId>& rxResourceId);
163 bool operator() (
const css::drawing::framework::ConfigurationChangeEvent& rEvent)
167 css::uno::Reference<css::drawing::framework::XResourceId>
mxResourceId;
197 ::std::shared_ptr< ViewShell > lcl_getViewShell(
const Reference< XResource >& i_rViewShellWrapper )
199 ::std::shared_ptr< ViewShell > pViewShell;
202 if (
auto pWrapper =
dynamic_cast<ViewShellWrapper*
>(i_rViewShellWrapper.get()))
203 pViewShell = pWrapper->GetViewShell();
205 catch(
const Exception& )
211 Reference< XResource > lcl_getFirstViewInPane(
const Reference< XConfigurationController >& i_rConfigController,
212 const Reference< XResourceId >& i_rPaneId )
216 Reference< XConfiguration > xConfiguration( i_rConfigController->getRequestedConfiguration(), UNO_SET_THROW );
217 Sequence< Reference< XResourceId > > aViewIds( xConfiguration->getResources(
219 if ( aViewIds.hasElements() )
220 return i_rConfigController->getResource( aViewIds[0] );
222 catch(
const Exception& )
236 :
public std::unordered_map<
238 ViewShell::ShellType>
248 css::lang::XEventListener
249 > FrameworkHelperDisposeListenerInterfaceBase;
253 :
public FrameworkHelperDisposeListenerInterfaceBase
258 virtual void disposing(std::unique_lock<std::mutex>&)
override;
260 virtual void SAL_CALL
disposing (
const lang::EventObject& rEventObject)
override;
288 InstanceMap::const_iterator iHelper (
maInstanceMap.find(&rBase));
290 return iHelper->second;
292 ::std::shared_ptr<FrameworkHelper> pHelper(
295 pHelper->Initialize();
306 iHelper->second->Dispose();
320 Reference<XControllerManager> xControllerManager (rBase.
GetController(), UNO_QUERY);
321 if (xControllerManager.is())
326 new LifetimeController(
mrBase);
353 return ::std::shared_ptr<ViewShell>();
361 return lcl_getViewShell( rxView );
366 Reference<XView> xView;
382 catch (lang::DisposedException&)
394 const OUString& rsResourceURL,
395 const OUString& rsAnchorURL)
397 Reference<XResourceId> xViewId;
405 ResourceActivationMode_ADD);
409 ResourceActivationMode_REPLACE);
412 catch (lang::DisposedException&)
438 ViewURLMap::const_iterator iView (
maViewURLMap.find(rsViewURL));
440 return iView->second;
465void updateEditMode(
const Reference<XView> &xView,
const EditMode eEMode,
bool updateFrameView)
473 if (pDrawViewShell !=
nullptr)
475 pCenterViewShell->Broadcast (
482 pCenterViewShell->Broadcast (
487void asyncUpdateEditMode(FrameworkHelper*
const pHelper,
const EditMode eEMode)
489 Reference<XResourceId> xPaneId (
491 Reference<XView> xView (pHelper->GetView(xPaneId));
492 updateEditMode(xView, eEMode,
true);
507 if (nSlotId == SID_NOTES_MASTER_MODE || nSlotId == SID_SLIDE_MASTER_MODE)
510 if (pRequestArguments)
515 if (nSlotId == SID_NOTES_MASTER_MODE)
516 nSlotId = SID_NOTES_MODE;
518 nSlotId = SID_NORMAL_MULTI_PANE_GUI;
528 Reference<XResourceId> xPaneId (
530 Reference<XView> xView (
GetView(xPaneId));
533 OUString sRequestedView;
537 case SID_DRAWINGMODE:
539 case SID_NORMAL_MULTI_PANE_GUI:
540 case SID_SLIDE_MASTER_MODE:
545 case SID_NOTES_MASTER_MODE:
549 case SID_HANDOUT_MASTER_MODE:
553 case SID_SLIDE_SORTER_MULTI_PANE_GUI:
554 case SID_SLIDE_SORTER_MODE:
558 case SID_OUTLINE_MODE:
565 if (nSlotId == SID_SLIDE_MASTER_MODE
566 || nSlotId == SID_NOTES_MASTER_MODE
567 || nSlotId == SID_HANDOUT_MASTER_MODE)
570 if (!(xView.is() && xView->getResourceId()->getResourceURL() == sRequestedView))
576 ResourceActivationMode_REPLACE);
581 updateEditMode(xView, eEMode,
false);
591 const OUString& rsEventType,
596 FrameworkHelperAllPassFilter(),
601 const css::uno::Reference<css::drawing::framework::XResourceId>& rxResourceId,
613 FrameworkHelperResourceIdFilter(rxResourceId),
626 explicit FlagUpdater (
bool& rFlag) :
mrFlag(rFlag) {}
627 void operator() (
bool)
const {
mrFlag =
true;}
639 pCC->RequestSynchronousUpdate();
644 bool bConfigurationUpdateSeen (
false);
648 FrameworkHelperAllPassFilter(),
649 FlagUpdater(bConfigurationUpdateSeen));
651 sal_uInt32 nStartTime = osl_getGlobalTimer();
652 while ( ! bConfigurationUpdateSeen)
656 if( (osl_getGlobalTimer() - nStartTime) > 60000 )
658 OSL_FAIL(
"FrameworkHelper::WaitForEvent(), no event for a minute? giving up!");
670 const OUString& rsEventType,
674 new CallbackCaller(
mrBase,rsEventType,rFilter,rCallback);
693 catch (lang::DisposedException&)
705 OUStringBuffer sString;
706 if (rxResourceId.is())
708 sString.append(rxResourceId->getResourceURL());
709 if (rxResourceId->hasAnchor())
711 const Sequence<OUString> aAnchorURLs (rxResourceId->getAnchorURLs());
712 for (
const auto& rAnchorURL : aAnchorURLs)
714 sString.append(
" | " + rAnchorURL);
718 return sString.makeStringAndClear();
723 return new ::sd::framework::ResourceId(rsResourceURL);
727 const OUString& rsResourceURL,
728 const OUString& rsAnchorURL)
730 return new ::sd::framework::ResourceId(rsResourceURL, rsAnchorURL);
734 const OUString& rsResourceURL,
735 const Reference<XResourceId>& rxAnchorId)
738 return new ::sd::framework::ResourceId(
740 rxAnchorId->getResourceURL(),
741 rxAnchorId->getAnchorURLs());
743 return new ::sd::framework::ResourceId(rsResourceURL);
749 ::std::shared_ptr<FrameworkHelper> pHelper)
750 : mpHelper(
std::move(pHelper))
752 Reference<XComponent> xComponent (
mpHelper->mxConfigurationController, UNO_QUERY);
754 xComponent->addEventListener(
this);
759 Reference<XComponent> xComponent (mpHelper->mxConfigurationController, UNO_QUERY);
761 xComponent->removeEventListener(
this);
768 if (mpHelper !=
nullptr)
769 mpHelper->disposing(rEventObject);
774FrameworkHelperResourceIdFilter::FrameworkHelperResourceIdFilter (
775 const Reference<XResourceId>& rxResourceId)
786CallbackCaller::CallbackCaller (
787 const ::sd::ViewShellBase& rBase,
788 OUString rsEventType,
791 : msEventType(
std::move(rsEventType)),
792 maFilter(
std::move(aFilter)),
793 maCallback(
std::move(aCallback))
797 Reference<XControllerManager> xControllerManager (rBase.GetController(), UNO_QUERY_THROW);
822void CallbackCaller::disposing(std::unique_lock<std::mutex>&)
830 xCC->removeConfigurationChangeListener(
this);
839void SAL_CALL CallbackCaller::disposing (
const lang::EventObject& rEvent)
848void SAL_CALL CallbackCaller::notifyConfigurationChange (
849 const ConfigurationChangeEvent& rEvent)
851 if (!(rEvent.Type == msEventType && maFilter(rEvent)))
864 xCC->removeConfigurationChangeListener(
this);
872 mbListeningToViewShellBase(false),
873 mbListeningToController(false)
882 mbListeningToViewShellBase =
true;
887 xComponent->addEventListener(
this);
888 mbListeningToController =
true;
892LifetimeController::~LifetimeController()
894 OSL_ASSERT(!mbListeningToController && !mbListeningToViewShellBase);
897void SAL_CALL LifetimeController::disposing (
const lang::EventObject&)
899 mbListeningToController =
false;
905 if (rHint.
GetId() == SfxHintId::Dying)
907 mbListeningToViewShellBase =
false;
913void LifetimeController::Update()
915 if (mbListeningToViewShellBase && mbListeningToController)
920 else if (mbListeningToViewShellBase)
css::uno::Reference< css::drawing::framework::XResourceId > mxResourceId
static bool Reschedule(bool bHandleAllCurrentEvents=false)
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint)
const SfxItemSet * GetArgs() const
const T * GetArg(sal_uInt16 nSlotId) const
css::uno::Reference< css::frame::XController > GetController() const
Base class of the stacked shells that provide graphical views to Draw and Impress documents and editi...
bool IsLayerModeActive() const
virtual void WriteFrameViewData() override
Apply data of the current view on the FrameView.
virtual void ChangeEditMode(EditMode eMode, bool bIsLayerModeActive)
Set status (enabled/disabled) of menu SfxSlots.
SfxViewShell descendant that the stacked Draw/Impress shells are based on.
Local derivation of the SfxHint class that defines some hint ids that are used by the ViewShell class...
@ HINT_CHANGE_EDIT_MODE_END
@ HINT_CHANGE_EDIT_MODE_START
The configuration controller is responsible for maintaining the current configuration.
void operator()(FrameworkHelper *pObject)
::std::shared_ptr< FrameworkHelper > mpHelper
virtual void disposing(std::unique_lock< std::mutex > &) override
DisposeListener(::std::shared_ptr< FrameworkHelper > pHelper)
The ViewURLMap is used to translate between the view URLs used by the drawing framework and the enums...
The FrameworkHelper is a convenience class that simplifies the access to the drawing framework.
FrameworkHelper(ViewShellBase &rBase)
void disposing(const css::lang::EventObject &rEventObject)
This disposing method is forwarded from the inner DisposeListener class.
static ::std::shared_ptr< ViewShell > GetViewShell(const css::uno::Reference< css::drawing::framework::XView > &rxView)
Return a ViewShell pointer for the given XView reference.
css::uno::Reference< css::drawing::framework::XResourceId > RequestView(const OUString &rsResourceURL, const OUString &rsAnchorURL)
Request the specified view to be displayed in the specified pane.
static std::mutex maInstanceMapMutex
void UpdateConfiguration()
Explicit request for an update of the current configuration.
static css::uno::Reference< css::drawing::framework::XResourceId > CreateResourceId(const OUString &rsResourceURL)
Create a new XResourceId object for the given resource URL.
static InstanceMap maInstanceMap
The instance map holds (at least) one FrameworkHelper instance for every ViewShellBase object.
::std::map< const ViewShellBase *, ::std::shared_ptr< FrameworkHelper > > InstanceMap
static const OUString msHandoutViewURL
static OUString GetViewURL(ViewShell::ShellType eType)
Return a view URL for the given identifier.
static const OUString msCenterPaneURL
void RunOnEvent(const OUString &rsEventType, const ConfigurationChangeEventFilter &rFilter, const Callback &rCallback) const
Run the given callback when an event of the specified type is received from the ConfigurationControll...
static const OUString msLeftDrawPaneURL
void HandleModeChangeSlot(sal_uInt16 nSlotId, SfxRequest const &rRequest)
Process a slot call that requests a view shell change.
void RunOnResourceActivation(const css::uno::Reference< css::drawing::framework::XResourceId > &rxResourceId, const Callback &rCallback)
Run the given callback when the specified resource has been activated.
static const OUString msNotesViewURL
static ViewShell::ShellType GetViewId(const OUString &rsViewURL)
Return an identifier for the given view URL.
static const OUString msOutlineViewURL
static constexpr OUStringLiteral msConfigurationUpdateEndEvent
void RunOnConfigurationEvent(const OUString &rsEventType, const Callback &rCallback)
Run the given callback when the specified event is notified by the ConfigurationManager.
void RequestSynchronousUpdate()
Normally the requested changes of the configuration are executed asynchronously.
::std::function< void(bool bEventSeen)> Callback
static const OUString msPresentationViewURL
static const OUString msSlideSorterURL
static ViewURLMap maViewURLMap
css::uno::Reference< css::drawing::framework::XView > GetView(const css::uno::Reference< css::drawing::framework::XResourceId > &rxPaneOrViewId)
Return a reference to the view that is displayed in the specified pane.
css::uno::Reference< css::lang::XComponent > mxDisposeListener
static const OUString msSidebarViewURL
static OUString ResourceIdToString(const css::uno::Reference< css::drawing::framework::XResourceId > &rxResourceId)
Return a string representation of the given XResourceId object.
static ::std::shared_ptr< FrameworkHelper > Instance(ViewShellBase &rBase)
Return the FrameworkHelper object that is associated with the given ViewShellBase.
static const OUString msLeftImpressPaneURL
void WaitForUpdate() const
This is a short cut for WaitForEvent(msConfigurationUpdateEndEvent).
friend class DisposeListener
static void ReleaseInstance(const ViewShellBase &rBase)
Destroy the FrameworkHelper object for the given ViewShellBase.
static const OUString msDrawViewURL
static constexpr OUStringLiteral msResourceActivationEvent
virtual ~FrameworkHelper() override
css::uno::Reference< css::drawing::framework::XConfigurationController > mxConfigurationController
::std::function< bool(const css::drawing::framework::ConfigurationChangeEvent &)> ConfigurationChangeEventFilter
static constexpr OUStringLiteral msViewURLPrefix
static const OUString msImpressViewURL
static const OUString msViewTabBarURL
static const OUString msFullScreenPaneURL
void WaitForEvent(const OUString &rsEventName) const
Block until the specified event is notified by the configuration controller.
static void DisposeInstance(const ViewShellBase &rBase)
Mark the FrameworkHelper object for the given ViewShellBase as disposed.
bool IsValid() const
Test whether the called FrameworkHelper object is valid.
#define DBG_UNHANDLED_EXCEPTION(...)
EmbeddedObjectRef * pObject
constexpr OUStringLiteral msPaneURLPrefix(u"private:resource/pane/")