1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: FrameworkHelper.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "precompiled_sd.hxx"
35 #include "framework/FrameworkHelper.hxx"
37 #include "framework/ConfigurationController.hxx"
38 #include "framework/ResourceId.hxx"
39 #include "framework/ViewShellWrapper.hxx"
40 #include "ViewShellBase.hxx"
41 #include "FrameView.hxx"
42 #include "DrawViewShell.hxx"
43 #include "ViewShellHint.hxx"
44 #include "DrawController.hxx"
46 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
47 #include <cppuhelper/compbase1.hxx>
48 #include <svtools/lstner.hxx>
50 #include <comphelper/stl_types.hxx>
51 #include <sfx2/request.hxx>
52 #include <sfx2/dispatch.hxx>
54 #include "MutexOwner.hxx"
55 #include "vcl/svapp.hxx"
56 #include <osl/doublecheckedlocking.h>
57 #include <osl/getglobalmutex.hxx>
59 using namespace ::com::sun::star
;
60 using namespace ::com::sun::star::uno
;
61 using namespace ::com::sun::star::drawing::framework
;
63 using ::rtl::OUString
;
68 //----- CallbackCaller --------------------------------------------------------
70 typedef ::cppu::WeakComponentImplHelper1
<
71 ::com::sun::star::drawing::framework::XConfigurationChangeListener
72 > CallbackCallerInterfaceBase
;
74 /** A CallbackCaller registers as listener at an XConfigurationController
75 object and waits for the notification of one type of event. When that
76 event is received, or when the CallbackCaller detects at its
77 construction that the event will not be sent in the near future, the
78 actual callback object is called and the CallbackCaller destroys itself.
81 : public ::sd::MutexOwner
,
82 public CallbackCallerInterfaceBase
85 /** Create a new CallbackCaller object. This object controls its own
86 lifetime by acquiring a reference to itself in the constructor.
87 When it detects that the event will not be notified in the near
88 future (because the queue of pending configuration change operations
89 is empty and therefore no event will be sent int the near future, it
90 does not acquires a reference and thus initiates its destruction in
93 This ViewShellBase object is used to determine the
94 XConfigurationController at which to register.
96 The event type which the callback is waiting for.
98 The callback object which is to be notified. The caller will
99 typically release his reference to the caller so that when the
100 CallbackCaller dies (after having called the callback) the
101 callback is destroyed.
104 ::sd::ViewShellBase
& rBase
,
105 const OUString
& rsEventType
,
106 const ::sd::framework::FrameworkHelper::ConfigurationChangeEventFilter
& rFilter
,
107 const ::sd::framework::FrameworkHelper::Callback
& rCallback
);
108 virtual ~CallbackCaller (void);
110 virtual void SAL_CALL
disposing (void);
111 virtual void SAL_CALL
disposing (const lang::EventObject
& rEvent
)
112 throw (RuntimeException
);
113 virtual void SAL_CALL
notifyConfigurationChange (const ConfigurationChangeEvent
& rEvent
)
114 throw (RuntimeException
);
117 OUString msEventType
;
118 Reference
<XConfigurationController
> mxConfigurationController
;
119 ::sd::framework::FrameworkHelper::ConfigurationChangeEventFilter maFilter
;
120 ::sd::framework::FrameworkHelper::Callback maCallback
;
126 //----- LifetimeController ----------------------------------------------------
128 typedef ::cppu::WeakComponentImplHelper1
<
129 ::com::sun::star::lang::XEventListener
130 > LifetimeControllerInterfaceBase
;
132 /** This class helps controling the lifetime of the
133 FrameworkHelper. Register at a ViewShellBase object and an XController
134 object and call Dispose() at the associated FrameworkHelper object when
135 one of them and Release() when both of them are destroyed.
137 class LifetimeController
138 : public ::sd::MutexOwner
,
139 public LifetimeControllerInterfaceBase
,
143 explicit LifetimeController (::sd::ViewShellBase
& rBase
);
144 virtual ~LifetimeController (void);
146 virtual void SAL_CALL
disposing (void);
148 /** XEventListener. This method is called when the frame::XController
151 virtual void SAL_CALL
disposing (const lang::EventObject
& rEvent
)
152 throw (RuntimeException
);
154 /** This method is called when the ViewShellBase is being destroyed.
156 virtual void Notify (SfxBroadcaster
& rBroadcaster
, const SfxHint
& rHint
);
159 ::sd::ViewShellBase
& mrBase
;
160 bool mbListeningToViewShellBase
;
161 bool mbListeningToController
;
163 /** When one or both of the mbListeningToViewShellBase and
164 mbListeningToController members were modified then call this method
165 to either dispose or release the associated FrameworkHelper.
172 } // end of anonymous namespace
174 namespace sd
{ namespace framework
{
178 const OUString
FrameworkHelper::msPaneURLPrefix(
179 OUString::createFromAscii("private:resource/pane/"));
180 const OUString
FrameworkHelper::msCenterPaneURL(
181 msPaneURLPrefix
+ OUString::createFromAscii("CenterPane"));
182 const OUString
FrameworkHelper::msFullScreenPaneURL(
183 msPaneURLPrefix
+ OUString::createFromAscii("FullScreenPane"));
184 const OUString
FrameworkHelper::msLeftImpressPaneURL(
185 msPaneURLPrefix
+ OUString::createFromAscii("LeftImpressPane"));
186 const OUString
FrameworkHelper::msLeftDrawPaneURL(
187 msPaneURLPrefix
+ OUString::createFromAscii("LeftDrawPane"));
188 const OUString
FrameworkHelper::msRightPaneURL(
189 msPaneURLPrefix
+ OUString::createFromAscii("RightPane"));
194 const OUString
FrameworkHelper::msViewURLPrefix(
195 OUString::createFromAscii("private:resource/view/"));
196 const OUString
FrameworkHelper::msImpressViewURL(
197 msViewURLPrefix
+ OUString::createFromAscii("ImpressView"));
198 const OUString
FrameworkHelper::msDrawViewURL(
199 msViewURLPrefix
+ OUString::createFromAscii("GraphicView"));
200 const OUString
FrameworkHelper::msOutlineViewURL(
201 msViewURLPrefix
+ OUString::createFromAscii("OutlineView"));
202 const OUString
FrameworkHelper::msNotesViewURL(
203 msViewURLPrefix
+ OUString::createFromAscii("NotesView"));
204 const OUString
FrameworkHelper::msHandoutViewURL(
205 msViewURLPrefix
+ OUString::createFromAscii("HandoutView"));
206 const OUString
FrameworkHelper::msSlideSorterURL(
207 msViewURLPrefix
+ OUString::createFromAscii("SlideSorter"));
208 const OUString
FrameworkHelper::msPresentationViewURL(
209 msViewURLPrefix
+ OUString::createFromAscii("PresentationView"));
210 const OUString
FrameworkHelper::msTaskPaneURL(
211 msViewURLPrefix
+ OUString::createFromAscii("TaskPane"));
216 const OUString
FrameworkHelper::msToolBarURLPrefix(
217 OUString::createFromAscii("private:resource/toolbar/"));
218 const OUString
FrameworkHelper::msViewTabBarURL(
219 msToolBarURLPrefix
+ OUString::createFromAscii("ViewTabBar"));
223 const ::rtl::OUString
FrameworkHelper::msTaskPanelURLPrefix(
224 OUString::createFromAscii("private:resource/taskpanel/"));
225 const ::rtl::OUString
FrameworkHelper::msMasterPagesTaskPanelURL(
226 msTaskPanelURLPrefix
+ OUString::createFromAscii("MasterPages"));
227 const ::rtl::OUString
FrameworkHelper::msLayoutTaskPanelURL(
228 msTaskPanelURLPrefix
+ OUString::createFromAscii("Layouts"));
229 const ::rtl::OUString
FrameworkHelper::msTableDesignPanelURL(
230 msTaskPanelURLPrefix
+ OUString::createFromAscii("TableDesign"));
231 const ::rtl::OUString
FrameworkHelper::msCustomAnimationTaskPanelURL(
232 msTaskPanelURLPrefix
+ OUString::createFromAscii("CustomAnimations"));
233 const ::rtl::OUString
FrameworkHelper::msSlideTransitionTaskPanelURL(
234 msTaskPanelURLPrefix
+ OUString::createFromAscii("SlideTransitions"));
238 const OUString
FrameworkHelper::msResourceActivationRequestEvent(
239 OUString::createFromAscii("ResourceActivationRequested"));
240 const OUString
FrameworkHelper::msResourceDeactivationRequestEvent(
241 OUString::createFromAscii("ResourceDeactivationRequest"));
242 const OUString
FrameworkHelper::msResourceActivationEvent(
243 OUString::createFromAscii("ResourceActivation"));
244 const OUString
FrameworkHelper::msResourceDeactivationEvent(
245 OUString::createFromAscii("ResourceDeactivation"));
246 const OUString
FrameworkHelper::msConfigurationUpdateStartEvent(
247 OUString::createFromAscii("ConfigurationUpdateStart"));
248 const OUString
FrameworkHelper::msConfigurationUpdateEndEvent(
249 OUString::createFromAscii("ConfigurationUpdateEnd"));
252 // Service names of controllers.
253 const OUString
FrameworkHelper::msModuleControllerService(
254 OUString::createFromAscii("com.sun.star.drawing.framework.ModuleController"));
255 const OUString
FrameworkHelper::msConfigurationControllerService(
256 OUString::createFromAscii("com.sun.star.drawing.framework.ConfigurationController"));
259 //----- FrameworkHelper::ViewURLMap -------------------------------------------
261 /** The ViewURLMap is used to translate between the view URLs used by the
262 drawing framework and the enums defined in the ViewShell class.
264 class FrameworkHelper::ViewURLMap
265 : public ::std::hash_map
<
267 ViewShell::ShellType
,
268 ::comphelper::UStringHash
,
269 ::comphelper::UStringEqual
>
278 //----- Framework::DiposeListener ---------------------------------------------
281 typedef ::cppu::WeakComponentImplHelper1
<
282 ::com::sun::star::lang::XEventListener
283 > FrameworkHelperDisposeListenerInterfaceBase
;
286 class FrameworkHelper::DisposeListener
287 : public ::sd::MutexOwner
,
288 public FrameworkHelperDisposeListenerInterfaceBase
291 DisposeListener (const ::boost::shared_ptr
<FrameworkHelper
>& rpHelper
);
292 ~DisposeListener (void);
294 virtual void SAL_CALL
disposing (void);
296 virtual void SAL_CALL
disposing (const lang::EventObject
& rEventObject
)
297 throw(RuntimeException
);
300 ::boost::shared_ptr
<FrameworkHelper
> mpHelper
;
306 //----- FrameworkHelper -------------------------------------------------------
308 ::boost::scoped_ptr
<FrameworkHelper::ViewURLMap
> FrameworkHelper::mpViewURLMap(new ViewURLMap());
311 FrameworkHelper::InstanceMap
FrameworkHelper::maInstanceMap
;
315 ::boost::shared_ptr
<FrameworkHelper
> FrameworkHelper::Instance (
316 const Reference
<frame::XController
>& rxController
)
318 // Tunnel through the controller to obtain a ViewShellBase.
319 Reference
<lang::XUnoTunnel
> xTunnel (rxController
, UNO_QUERY
);
322 ::sd::DrawController
* pController
= reinterpret_cast<sd::DrawController
*>(
323 xTunnel
->getSomething(sd::DrawController::getUnoTunnelId()));
324 if (pController
!= NULL
)
326 ViewShellBase
* pBase
= pController
->GetViewShellBase();
328 return Instance(*pBase
);
332 return ::boost::shared_ptr
<FrameworkHelper
>();
338 ::boost::shared_ptr
<FrameworkHelper
> FrameworkHelper::Instance (ViewShellBase
& rBase
)
341 ::boost::shared_ptr
<FrameworkHelper
> pHelper
;
343 InstanceMap::const_iterator
iHelper (maInstanceMap
.find(&rBase
));
344 if (iHelper
== maInstanceMap
.end())
346 ::osl::GetGlobalMutex aMutexFunctor
;
347 ::osl::MutexGuard
aGuard (aMutexFunctor());
348 if (iHelper
== maInstanceMap
.end())
350 pHelper
= ::boost::shared_ptr
<FrameworkHelper
>(new FrameworkHelper(rBase
));
351 pHelper
->Initialize();
352 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
353 SdGlobalResourceContainer::Instance().AddResource(pHelper
);
354 maInstanceMap
[&rBase
] = pHelper
;
359 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
360 pHelper
= iHelper
->second
;
369 void FrameworkHelper::DisposeInstance (ViewShellBase
& rBase
)
371 InstanceMap::iterator
iHelper (maInstanceMap
.find(&rBase
));
372 if (iHelper
!= maInstanceMap
.end())
374 iHelper
->second
->Dispose();
381 void FrameworkHelper::ReleaseInstance (ViewShellBase
& rBase
)
383 InstanceMap::iterator
iHelper (maInstanceMap
.find(&rBase
));
384 if (iHelper
!= maInstanceMap
.end())
385 maInstanceMap
.erase(iHelper
);
391 FrameworkHelper::FrameworkHelper (ViewShellBase
& rBase
)
393 mxConfigurationController(),
397 Reference
<XControllerManager
> xControllerManager (rBase
.GetController(), UNO_QUERY
);
398 if (xControllerManager
.is())
400 mxConfigurationController
= xControllerManager
->getConfigurationController();
403 new LifetimeController(mrBase
);
409 void FrameworkHelper::Initialize (void)
411 mxDisposeListener
= new DisposeListener(shared_from_this());
417 FrameworkHelper::~FrameworkHelper (void)
424 void FrameworkHelper::Dispose (void)
426 if (mxDisposeListener
.is())
427 mxDisposeListener
->dispose();
428 mxConfigurationController
= NULL
;
434 bool FrameworkHelper::IsValid (void)
436 return mxConfigurationController
.is();
442 ::boost::shared_ptr
<ViewShell
> FrameworkHelper::GetViewShell (const OUString
& rsPaneURL
)
444 Reference
<XResourceId
> xPaneId (CreateResourceId(rsPaneURL
));
445 return GetViewShell(GetView(xPaneId
));
451 ::boost::shared_ptr
<ViewShell
> FrameworkHelper::GetViewShell (const Reference
<XView
>& rxView
)
453 ::boost::shared_ptr
<ViewShell
> pViewShell
;
457 Reference
<lang::XUnoTunnel
> xViewTunnel (rxView
, UNO_QUERY
);
458 if (xViewTunnel
.is())
460 pViewShell
= reinterpret_cast<ViewShellWrapper
*>(xViewTunnel
->getSomething(
461 ViewShellWrapper::getUnoTunnelId()))->GetViewShell();
464 catch (RuntimeException
&)
474 Reference
<XView
> FrameworkHelper::GetView (const Reference
<XResourceId
>& rxPaneOrViewId
)
476 Reference
<XView
> xView
;
478 if ( ! rxPaneOrViewId
.is() || ! mxConfigurationController
.is())
483 if (rxPaneOrViewId
->getResourceURL().match(msViewURLPrefix
))
485 xView
= Reference
<XView
>(
486 mxConfigurationController
->getResource(rxPaneOrViewId
), UNO_QUERY
);
490 Reference
<XConfiguration
> xConfiguration (
491 mxConfigurationController
->getRequestedConfiguration());
492 if (xConfiguration
.is())
494 Sequence
<Reference
<XResourceId
> > aViewIds (xConfiguration
->getResources(
495 rxPaneOrViewId
, msViewURLPrefix
, AnchorBindingMode_DIRECT
));
496 if (aViewIds
.getLength() >= 1)
497 xView
= Reference
<XView
>(
498 mxConfigurationController
->getResource(aViewIds
[0]), UNO_QUERY
);
502 catch (lang::DisposedException
&)
506 catch (RuntimeException
&)
515 Reference
<XResourceId
> FrameworkHelper::RequestView (
516 const OUString
& rsResourceURL
,
517 const OUString
& rsAnchorURL
)
519 Reference
<XResourceId
> xViewId
;
523 if (mxConfigurationController
.is())
525 mxConfigurationController
->requestResourceActivation(
526 CreateResourceId(rsAnchorURL
),
527 ResourceActivationMode_ADD
);
528 xViewId
= CreateResourceId(rsResourceURL
, rsAnchorURL
);
529 mxConfigurationController
->requestResourceActivation(
531 ResourceActivationMode_REPLACE
);
534 catch (lang::DisposedException
&)
539 catch (RuntimeException
&)
550 void FrameworkHelper::RequestTaskPanel (
551 const OUString
& rsTaskPanelURL
)
555 if (mxConfigurationController
.is())
557 // Create the resource id from URLs for the pane, the task pane
558 // view, and the task panel.
559 mxConfigurationController
->requestResourceActivation(
560 CreateResourceId(msRightPaneURL
),
561 ResourceActivationMode_ADD
);
562 mxConfigurationController
->requestResourceActivation(
563 CreateResourceId(msTaskPaneURL
, msRightPaneURL
),
564 ResourceActivationMode_REPLACE
);
565 mxConfigurationController
->requestResourceActivation(
566 CreateResourceId(rsTaskPanelURL
, msTaskPaneURL
, msRightPaneURL
),
567 ResourceActivationMode_REPLACE
);
570 catch (lang::DisposedException
&)
574 catch (RuntimeException
&)
581 ViewShell::ShellType
FrameworkHelper::GetViewId (const rtl::OUString
& rsViewURL
)
583 if (mpViewURLMap
->empty())
585 (*mpViewURLMap
)[msImpressViewURL
] = ViewShell::ST_IMPRESS
;
586 (*mpViewURLMap
)[msDrawViewURL
] = ViewShell::ST_DRAW
;
587 (*mpViewURLMap
)[msOutlineViewURL
] = ViewShell::ST_OUTLINE
;
588 (*mpViewURLMap
)[msNotesViewURL
] = ViewShell::ST_NOTES
;
589 (*mpViewURLMap
)[msHandoutViewURL
] = ViewShell::ST_HANDOUT
;
590 (*mpViewURLMap
)[msSlideSorterURL
] = ViewShell::ST_SLIDE_SORTER
;
591 (*mpViewURLMap
)[msPresentationViewURL
] = ViewShell::ST_PRESENTATION
;
592 (*mpViewURLMap
)[msTaskPaneURL
] = ViewShell::ST_TASK_PANE
;
594 ViewURLMap::const_iterator
iView (mpViewURLMap
->find(rsViewURL
));
595 if (iView
!= mpViewURLMap
->end())
596 return iView
->second
;
598 return ViewShell::ST_NONE
;
604 ::rtl::OUString
FrameworkHelper::GetViewURL (ViewShell::ShellType eType
)
608 case ViewShell::ST_IMPRESS
: return msImpressViewURL
;
609 case ViewShell::ST_DRAW
: return msDrawViewURL
;
610 case ViewShell::ST_OUTLINE
: return msOutlineViewURL
;
611 case ViewShell::ST_NOTES
: return msNotesViewURL
;
612 case ViewShell::ST_HANDOUT
: return msHandoutViewURL
;
613 case ViewShell::ST_SLIDE_SORTER
: return msSlideSorterURL
;
614 case ViewShell::ST_PRESENTATION
: return msPresentationViewURL
;
615 case ViewShell::ST_TASK_PANE
: return msTaskPaneURL
;
624 void FrameworkHelper::HandleModeChangeSlot (
626 SfxRequest
& rRequest
)
628 BOOL bIsActive
= TRUE
;
630 if ( ! mxConfigurationController
.is())
635 case SID_DRAWINGMODE
:
637 case SID_HANDOUTMODE
:
639 case SID_OUTLINEMODE
:
641 const SfxItemSet
* pRequestArguments
= rRequest
.GetArgs();
642 if (pRequestArguments
)
644 SFX_REQUEST_ARG (rRequest
,
649 bIsActive
= pIsActive
->GetValue ();
657 if ( ! mxConfigurationController
.is())
658 throw RuntimeException();
661 Reference
<XResourceId
> xPaneId (
662 CreateResourceId(framework::FrameworkHelper::msCenterPaneURL
));
663 Reference
<XView
> xView (GetView(xPaneId
));
664 ::boost::shared_ptr
<ViewShell
> pCenterViewShell (GetViewShell(xView
));
666 ::rtl::OUString sRequestedView
;
671 case SID_NORMAL_MULTI_PANE_GUI
:
672 case SID_DRAWINGMODE
:
673 sRequestedView
= FrameworkHelper::msImpressViewURL
;
677 sRequestedView
= FrameworkHelper::msNotesViewURL
;
680 case SID_HANDOUTMODE
:
681 sRequestedView
= FrameworkHelper::msHandoutViewURL
;
684 case SID_SLIDE_SORTER_MULTI_PANE_GUI
:
686 sRequestedView
= FrameworkHelper::msSlideSorterURL
;
689 case SID_OUTLINEMODE
:
690 sRequestedView
= FrameworkHelper::msOutlineViewURL
;
696 && xView
->getResourceId()->getResourceURL().equals(sRequestedView
))
698 // We do not have to switch the view shell but maybe the edit mode
700 DrawViewShell
* pDrawViewShell
701 = dynamic_cast<DrawViewShell
*>(pCenterViewShell
.get());
702 if (pDrawViewShell
!= NULL
)
704 pCenterViewShell
->Broadcast (
705 ViewShellHint(ViewShellHint::HINT_CHANGE_EDIT_MODE_START
));
707 pDrawViewShell
->ChangeEditMode (
708 EM_PAGE
, pDrawViewShell
->IsLayerModeActive());
710 pCenterViewShell
->Broadcast (
711 ViewShellHint(ViewShellHint::HINT_CHANGE_EDIT_MODE_END
));
716 mxConfigurationController
->requestResourceActivation(
717 CreateResourceId(sRequestedView
, msCenterPaneURL
),
718 ResourceActivationMode_REPLACE
);
721 catch (RuntimeException
&)
723 OSL_TRACE("HandleModeChangeSlot: caught exception");
730 void FrameworkHelper::RunOnConfigurationEvent(
731 const ::rtl::OUString
& rsEventType
,
732 const Callback
& rCallback
)
736 FrameworkHelperAllPassFilter(),
743 void FrameworkHelper::RunOnResourceActivation(
744 const css::uno::Reference
<css::drawing::framework::XResourceId
>& rxResourceId
,
745 const Callback
& rCallback
)
747 if (mxConfigurationController
.is()
748 && mxConfigurationController
->getResource(rxResourceId
).is())
755 msResourceActivationEvent
,
756 FrameworkHelperResourceIdFilter(rxResourceId
),
764 /** A callback that sets a flag to a specified value when the callback is
770 FlagUpdater (bool& rFlag
) : mrFlag(rFlag
) {}
771 void operator() (bool) {mrFlag
= true;}
779 void FrameworkHelper::RequestSynchronousUpdate (void)
781 rtl::Reference
<ConfigurationController
> pCC (
782 dynamic_cast<ConfigurationController
*>(mxConfigurationController
.get()));
784 pCC
->RequestSynchronousUpdate();
790 void FrameworkHelper::WaitForEvent (const OUString
& rsEventType
) const
792 bool bConfigurationUpdateSeen (false);
796 FrameworkHelperAllPassFilter(),
797 FlagUpdater(bConfigurationUpdateSeen
));
799 sal_uInt32 nStartTime
= osl_getGlobalTimer();
800 while ( ! bConfigurationUpdateSeen
)
802 Application::Reschedule();
804 if( (osl_getGlobalTimer() - nStartTime
) > 60000 )
806 DBG_ERROR("FrameworkHelper::WaitForEvent(), no event since a minute? giving up!");
815 void FrameworkHelper::WaitForUpdate (void) const
817 WaitForEvent(msConfigurationUpdateEndEvent
);
823 void FrameworkHelper::RunOnEvent(
824 const ::rtl::OUString
& rsEventType
,
825 const ConfigurationChangeEventFilter
& rFilter
,
826 const Callback
& rCallback
) const
828 new CallbackCaller(mrBase
,rsEventType
,rFilter
,rCallback
);
834 void FrameworkHelper::disposing (const lang::EventObject
& rEventObject
)
836 if (rEventObject
.Source
== mxConfigurationController
)
837 mxConfigurationController
= NULL
;
843 void FrameworkHelper::UpdateConfiguration (void)
845 if (mxConfigurationController
.is())
849 if (mxConfigurationController
.is())
850 mxConfigurationController
->update();
852 catch (lang::DisposedException
&)
856 catch (RuntimeException
&)
858 DBG_ASSERT(false, "FrameworkHelper::UpdateConfiguration: caught exception");
866 OUString
FrameworkHelper::ResourceIdToString (const Reference
<XResourceId
>& rxResourceId
)
869 if (rxResourceId
.is())
871 sString
+= rxResourceId
->getResourceURL();
872 if (rxResourceId
->hasAnchor())
874 Sequence
<OUString
> aAnchorURLs (rxResourceId
->getAnchorURLs());
875 for (sal_Int32 nIndex
=0; nIndex
<aAnchorURLs
.getLength(); ++nIndex
)
877 sString
+= OUString::createFromAscii(" | ");
878 sString
+= aAnchorURLs
[nIndex
];
888 Reference
<XResourceId
> FrameworkHelper::CreateResourceId (const ::rtl::OUString
& rsResourceURL
)
890 return new ::sd::framework::ResourceId(rsResourceURL
);
896 Reference
<XResourceId
> FrameworkHelper::CreateResourceId (
897 const OUString
& rsResourceURL
,
898 const OUString
& rsAnchorURL
)
900 return new ::sd::framework::ResourceId(rsResourceURL
, rsAnchorURL
);
906 Reference
<XResourceId
> FrameworkHelper::CreateResourceId (
907 const OUString
& rsResourceURL
,
908 const OUString
& rsFirstAnchorURL
,
909 const OUString
& rsSecondAnchorURL
)
911 ::std::vector
<OUString
> aAnchorURLs (2);
912 aAnchorURLs
[0] = rsFirstAnchorURL
;
913 aAnchorURLs
[1] = rsSecondAnchorURL
;
914 return new ::sd::framework::ResourceId(rsResourceURL
, aAnchorURLs
);
920 Reference
<XResourceId
> FrameworkHelper::CreateResourceId (
921 const ::rtl::OUString
& rsResourceURL
,
922 const Reference
<XResourceId
>& rxAnchorId
)
925 return new ::sd::framework::ResourceId(
927 rxAnchorId
->getResourceURL(),
928 rxAnchorId
->getAnchorURLs());
930 return new ::sd::framework::ResourceId(rsResourceURL
);
936 Reference
<XConfigurationController
> FrameworkHelper::GetConfigurationController (void) const
938 return mxConfigurationController
;
944 //----- FrameworkHelper::DisposeListener --------------------------------------
946 FrameworkHelper::DisposeListener::DisposeListener (
947 const ::boost::shared_ptr
<FrameworkHelper
>& rpHelper
)
948 : FrameworkHelperDisposeListenerInterfaceBase(maMutex
),
951 Reference
<XComponent
> xComponent (mpHelper
->mxConfigurationController
, UNO_QUERY
);
953 xComponent
->addEventListener(this);
959 FrameworkHelper::DisposeListener::~DisposeListener (void)
966 void SAL_CALL
FrameworkHelper::DisposeListener::disposing (void)
968 Reference
<XComponent
> xComponent (mpHelper
->mxConfigurationController
, UNO_QUERY
);
970 xComponent
->removeEventListener(this);
978 void SAL_CALL
FrameworkHelper::DisposeListener::disposing (const lang::EventObject
& rEventObject
)
979 throw(RuntimeException
)
981 if (mpHelper
.get() != NULL
)
982 mpHelper
->disposing(rEventObject
);
988 //----- DispatchCaller --------------------------------------------------------
990 DispatchCaller::DispatchCaller (
991 SfxDispatcher
& rDispatcher
,
993 : mrDispatcher(rDispatcher
),
1001 void DispatchCaller::operator() (bool bEventSeen
)
1004 mrDispatcher
.Execute(mnSId
, SFX_CALLMODE_ASYNCHRON
| SFX_CALLMODE_RECORD
);
1010 //===== FrameworkHelperResourceIdFilter =======================================
1012 FrameworkHelperResourceIdFilter::FrameworkHelperResourceIdFilter (
1013 const Reference
<XResourceId
>& rxResourceId
)
1014 : mxResourceId(rxResourceId
)
1019 } } // end of namespace sd::framework
1023 //===== CallbackCaller ========================================================
1025 CallbackCaller::CallbackCaller (
1026 ::sd::ViewShellBase
& rBase
,
1027 const OUString
& rsEventType
,
1028 const ::sd::framework::FrameworkHelper::ConfigurationChangeEventFilter
& rFilter
,
1029 const ::sd::framework::FrameworkHelper::Callback
& rCallback
)
1030 : CallbackCallerInterfaceBase(MutexOwner::maMutex
),
1031 msEventType(rsEventType
),
1032 mxConfigurationController(),
1034 maCallback(rCallback
)
1038 Reference
<XControllerManager
> xControllerManager (rBase
.GetController(), UNO_QUERY_THROW
);
1039 mxConfigurationController
= xControllerManager
->getConfigurationController();
1040 if (mxConfigurationController
.is())
1042 if (mxConfigurationController
->hasPendingRequests())
1043 mxConfigurationController
->addConfigurationChangeListener(this,msEventType
,Any());
1046 // There are no requests waiting to be processed. Therefore
1047 // no event, especially not the one we are waiting for, will
1048 // be sent in the near future and the callback would never be
1050 // Call the callback now and tell him that the event it is
1051 // waiting for was not sent.
1052 mxConfigurationController
= NULL
;
1057 catch (RuntimeException
&)
1059 DBG_ASSERT(false,"ConfigurationUpdateGuard: caught exception");
1066 CallbackCaller::~CallbackCaller (void)
1073 void CallbackCaller::disposing (void)
1077 if (mxConfigurationController
.is())
1079 Reference
<XConfigurationController
> xCC (mxConfigurationController
);
1080 mxConfigurationController
= NULL
;
1081 xCC
->removeConfigurationChangeListener(this);
1084 catch (RuntimeException
&)
1086 DBG_ASSERT(false,"~ConfigurationUpdateGuard: caught exception");
1093 void SAL_CALL
CallbackCaller::disposing (const lang::EventObject
& rEvent
)
1094 throw (RuntimeException
)
1096 if (rEvent
.Source
== mxConfigurationController
)
1098 mxConfigurationController
= NULL
;
1106 void SAL_CALL
CallbackCaller::notifyConfigurationChange (
1107 const ConfigurationChangeEvent
& rEvent
)
1108 throw (RuntimeException
)
1110 if (rEvent
.Type
.equals(msEventType
) && maFilter(rEvent
))
1113 if (mxConfigurationController
.is())
1115 // Reset the reference to the configuration controller so that
1116 // dispose() will not try to remove the listener a second time.
1117 Reference
<XConfigurationController
> xCC (mxConfigurationController
);
1118 mxConfigurationController
= NULL
;
1120 // Removing this object from the controller may very likely lead
1121 // to its destruction, so no calls after that.
1122 xCC
->removeConfigurationChangeListener(this);
1130 //----- LifetimeController -------------------------------------------------
1132 LifetimeController::LifetimeController (::sd::ViewShellBase
& rBase
)
1133 : LifetimeControllerInterfaceBase(maMutex
),
1135 mbListeningToViewShellBase(false),
1136 mbListeningToController(false)
1138 // Register as listener at the ViewShellBase. Because that is not done
1139 // via a reference we have to increase the reference count manually.
1140 // This is necessary even though listening to the XController did
1141 // increase the reference count because the controller may release its
1142 // reference to us before the ViewShellBase is destroyed.
1143 StartListening(mrBase
);
1145 mbListeningToViewShellBase
= true;
1147 Reference
<XComponent
> xComponent (rBase
.GetController(), UNO_QUERY
);
1148 if (xComponent
.is())
1150 xComponent
->addEventListener(this);
1151 mbListeningToController
= true;
1158 LifetimeController::~LifetimeController (void)
1160 OSL_ASSERT(!mbListeningToController
&& !mbListeningToViewShellBase
);
1166 void LifetimeController::disposing (void)
1173 void SAL_CALL
LifetimeController::disposing (const lang::EventObject
& rEvent
)
1174 throw(RuntimeException
)
1177 mbListeningToController
= false;
1184 void LifetimeController::Notify (SfxBroadcaster
& rBroadcaster
, const SfxHint
& rHint
)
1187 const SfxSimpleHint
* pSimpleHint
= dynamic_cast<const SfxSimpleHint
*>(&rHint
);
1188 if (pSimpleHint
!= NULL
&& pSimpleHint
->GetId() == SFX_HINT_DYING
)
1190 mbListeningToViewShellBase
= false;
1199 void LifetimeController::Update (void)
1201 if (mbListeningToViewShellBase
&& mbListeningToController
)
1203 // Both the controller and the ViewShellBase are alive. Keep
1204 // waiting for their destruction.
1206 else if (mbListeningToViewShellBase
)
1208 // The controller has been destroyed but the ViewShellBase is still
1209 // alive. Dispose the associated FrameworkHelper but keep it around
1210 // so that no new instance is created for the dying framework.
1211 ::sd::framework::FrameworkHelper::DisposeInstance(mrBase
);
1215 // Both the controller and the ViewShellBase have been destroyed.
1216 // Remove the FrameworkHelper so that the next call its Instance()
1217 // method can create a new instance.
1218 ::sd::framework::FrameworkHelper::ReleaseInstance(mrBase
);
1224 } // end of anonymous namespace.