15b190011SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
35b190011SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
45b190011SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
55b190011SAndrew Rist  * distributed with this work for additional information
65b190011SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
75b190011SAndrew Rist  * to you under the Apache License, Version 2.0 (the
85b190011SAndrew Rist  * "License"); you may not use this file except in compliance
95b190011SAndrew Rist  * with the License.  You may obtain a copy of the License at
105b190011SAndrew Rist  *
115b190011SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
125b190011SAndrew Rist  *
135b190011SAndrew Rist  * Unless required by applicable law or agreed to in writing,
145b190011SAndrew Rist  * software distributed under the License is distributed on an
155b190011SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
165b190011SAndrew Rist  * KIND, either express or implied.  See the License for the
175b190011SAndrew Rist  * specific language governing permissions and limitations
185b190011SAndrew Rist  * under the License.
195b190011SAndrew Rist  *
205b190011SAndrew Rist  *************************************************************/
215b190011SAndrew Rist 
22cdf0e10cSrcweir #include "precompiled_sd.hxx"
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include <osl/time.h>
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "framework/FrameworkHelper.hxx"
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include "framework/ConfigurationController.hxx"
29cdf0e10cSrcweir #include "framework/ResourceId.hxx"
30cdf0e10cSrcweir #include "framework/ViewShellWrapper.hxx"
31cdf0e10cSrcweir #include "ViewShellBase.hxx"
32cdf0e10cSrcweir #include "FrameView.hxx"
33cdf0e10cSrcweir #include "DrawViewShell.hxx"
34cdf0e10cSrcweir #include "ViewShellHint.hxx"
35cdf0e10cSrcweir #include "DrawController.hxx"
36cdf0e10cSrcweir #include "app.hrc"
37cdf0e10cSrcweir #include <com/sun/star/drawing/framework/XControllerManager.hpp>
38*7a32b0c8SAndre Fischer #include <com/sun/star/drawing/framework/XPane.hpp>
39cdf0e10cSrcweir #include <cppuhelper/compbase1.hxx>
40cdf0e10cSrcweir #include <svl/lstner.hxx>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir #include <comphelper/stl_types.hxx>
43cdf0e10cSrcweir #include <sfx2/request.hxx>
44cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
45cdf0e10cSrcweir 
46cdf0e10cSrcweir #include "MutexOwner.hxx"
47cdf0e10cSrcweir #include "vcl/svapp.hxx"
48cdf0e10cSrcweir #include <osl/doublecheckedlocking.h>
49cdf0e10cSrcweir #include <osl/getglobalmutex.hxx>
50cdf0e10cSrcweir #include <tools/diagnose_ex.h>
51cdf0e10cSrcweir 
52cdf0e10cSrcweir using namespace ::com::sun::star;
53cdf0e10cSrcweir using namespace ::com::sun::star::uno;
54cdf0e10cSrcweir using namespace ::com::sun::star::drawing::framework;
55cdf0e10cSrcweir 
56cdf0e10cSrcweir using ::rtl::OUString;
57cdf0e10cSrcweir 
58cdf0e10cSrcweir namespace {
59cdf0e10cSrcweir 
60cdf0e10cSrcweir 
61cdf0e10cSrcweir //----- CallbackCaller --------------------------------------------------------
62cdf0e10cSrcweir 
63cdf0e10cSrcweir typedef ::cppu::WeakComponentImplHelper1 <
64cdf0e10cSrcweir     ::com::sun::star::drawing::framework::XConfigurationChangeListener
65cdf0e10cSrcweir     > CallbackCallerInterfaceBase;
66cdf0e10cSrcweir 
67cdf0e10cSrcweir /** A CallbackCaller registers as listener at an XConfigurationController
68cdf0e10cSrcweir     object and waits for the notification of one type of event.  When that
69cdf0e10cSrcweir     event is received, or when the CallbackCaller detects at its
70cdf0e10cSrcweir     construction that the event will not be sent in the near future, the
71cdf0e10cSrcweir     actual callback object is called and the CallbackCaller destroys itself.
72cdf0e10cSrcweir */
73cdf0e10cSrcweir class CallbackCaller
74cdf0e10cSrcweir     : public ::sd::MutexOwner,
75cdf0e10cSrcweir       public CallbackCallerInterfaceBase
76cdf0e10cSrcweir {
77cdf0e10cSrcweir public:
78cdf0e10cSrcweir     /** Create a new CallbackCaller object.  This object controls its own
79cdf0e10cSrcweir         lifetime by acquiring a reference to itself in the constructor.
80cdf0e10cSrcweir         When it detects that the event will not be notified in the near
81cdf0e10cSrcweir         future (because the queue of pending configuration change operations
82cdf0e10cSrcweir         is empty and therefore no event will be sent int the near future, it
83cdf0e10cSrcweir         does not acquires a reference and thus initiates its destruction in
84cdf0e10cSrcweir         the constructor.)
85cdf0e10cSrcweir         @param rBase
86cdf0e10cSrcweir             This ViewShellBase object is used to determine the
87cdf0e10cSrcweir             XConfigurationController at which to register.
88cdf0e10cSrcweir         @param rsEventType
89cdf0e10cSrcweir             The event type which the callback is waiting for.
90cdf0e10cSrcweir         @param pCallback
91cdf0e10cSrcweir             The callback object which is to be notified.  The caller will
92cdf0e10cSrcweir             typically release his reference to the caller so that when the
93cdf0e10cSrcweir             CallbackCaller dies (after having called the callback) the
94cdf0e10cSrcweir             callback is destroyed.
95cdf0e10cSrcweir     */
96cdf0e10cSrcweir     CallbackCaller (
97cdf0e10cSrcweir         ::sd::ViewShellBase& rBase,
98cdf0e10cSrcweir         const OUString& rsEventType,
99cdf0e10cSrcweir         const ::sd::framework::FrameworkHelper::ConfigurationChangeEventFilter& rFilter,
100cdf0e10cSrcweir         const ::sd::framework::FrameworkHelper::Callback& rCallback);
101cdf0e10cSrcweir     virtual ~CallbackCaller (void);
102cdf0e10cSrcweir 
103cdf0e10cSrcweir     virtual void SAL_CALL disposing (void);
104*7a32b0c8SAndre Fischer     // XEventListener
105cdf0e10cSrcweir     virtual void SAL_CALL disposing (const lang::EventObject& rEvent)
106cdf0e10cSrcweir         throw (RuntimeException);
107*7a32b0c8SAndre Fischer     // XConfigurationChangeListener
108cdf0e10cSrcweir     virtual void SAL_CALL notifyConfigurationChange (const ConfigurationChangeEvent& rEvent)
109cdf0e10cSrcweir         throw (RuntimeException);
110cdf0e10cSrcweir 
111cdf0e10cSrcweir private:
112cdf0e10cSrcweir     OUString msEventType;
113cdf0e10cSrcweir     Reference<XConfigurationController> mxConfigurationController;
114cdf0e10cSrcweir     ::sd::framework::FrameworkHelper::ConfigurationChangeEventFilter maFilter;
115cdf0e10cSrcweir     ::sd::framework::FrameworkHelper::Callback maCallback;
116cdf0e10cSrcweir };
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 
121cdf0e10cSrcweir //----- LifetimeController ----------------------------------------------------
122cdf0e10cSrcweir 
123cdf0e10cSrcweir typedef ::cppu::WeakComponentImplHelper1 <
124cdf0e10cSrcweir     ::com::sun::star::lang::XEventListener
125cdf0e10cSrcweir     > LifetimeControllerInterfaceBase;
126cdf0e10cSrcweir 
127cdf0e10cSrcweir /** This class helps controling the lifetime of the
128cdf0e10cSrcweir     FrameworkHelper. Register at a ViewShellBase object and an XController
129cdf0e10cSrcweir     object and call Dispose() at the associated FrameworkHelper object when
130cdf0e10cSrcweir     one of them and Release() when both of them are destroyed.
131cdf0e10cSrcweir */
132cdf0e10cSrcweir class LifetimeController
133cdf0e10cSrcweir     : public ::sd::MutexOwner,
134cdf0e10cSrcweir       public LifetimeControllerInterfaceBase,
135cdf0e10cSrcweir       public SfxListener
136cdf0e10cSrcweir {
137cdf0e10cSrcweir public:
138cdf0e10cSrcweir     explicit LifetimeController (::sd::ViewShellBase& rBase);
139cdf0e10cSrcweir     virtual ~LifetimeController (void);
140cdf0e10cSrcweir 
141cdf0e10cSrcweir     virtual void SAL_CALL disposing (void);
142cdf0e10cSrcweir 
143cdf0e10cSrcweir     /** XEventListener.  This method is called when the frame::XController
144cdf0e10cSrcweir         is being destroyed.
145cdf0e10cSrcweir     */
146cdf0e10cSrcweir     virtual void SAL_CALL disposing (const lang::EventObject& rEvent)
147cdf0e10cSrcweir         throw (RuntimeException);
148cdf0e10cSrcweir 
149cdf0e10cSrcweir     /** This method is called when the ViewShellBase is being destroyed.
150cdf0e10cSrcweir     */
151cdf0e10cSrcweir     virtual void Notify (SfxBroadcaster& rBroadcaster, const SfxHint& rHint);
152cdf0e10cSrcweir 
153cdf0e10cSrcweir private:
154cdf0e10cSrcweir     ::sd::ViewShellBase& mrBase;
155cdf0e10cSrcweir     bool mbListeningToViewShellBase;
156cdf0e10cSrcweir     bool mbListeningToController;
157cdf0e10cSrcweir 
158cdf0e10cSrcweir     /** When one or both of the mbListeningToViewShellBase and
159cdf0e10cSrcweir         mbListeningToController members were modified then call this method
160cdf0e10cSrcweir         to either dispose or release the associated FrameworkHelper.
161cdf0e10cSrcweir     */
162cdf0e10cSrcweir     void Update (void);
163cdf0e10cSrcweir };
164cdf0e10cSrcweir 
165cdf0e10cSrcweir 
166cdf0e10cSrcweir 
167cdf0e10cSrcweir } // end of anonymous namespace
168cdf0e10cSrcweir 
169cdf0e10cSrcweir namespace sd { namespace framework {
170cdf0e10cSrcweir 
171cdf0e10cSrcweir // Pane URLS.
172cdf0e10cSrcweir 
173cdf0e10cSrcweir const OUString FrameworkHelper::msPaneURLPrefix(
174cdf0e10cSrcweir     OUString::createFromAscii("private:resource/pane/"));
175cdf0e10cSrcweir const OUString FrameworkHelper::msCenterPaneURL(
176cdf0e10cSrcweir     msPaneURLPrefix + OUString::createFromAscii("CenterPane"));
177cdf0e10cSrcweir const OUString FrameworkHelper::msFullScreenPaneURL(
178cdf0e10cSrcweir     msPaneURLPrefix + OUString::createFromAscii("FullScreenPane"));
179cdf0e10cSrcweir const OUString FrameworkHelper::msLeftImpressPaneURL(
180cdf0e10cSrcweir     msPaneURLPrefix + OUString::createFromAscii("LeftImpressPane"));
181cdf0e10cSrcweir const OUString FrameworkHelper::msLeftDrawPaneURL(
182cdf0e10cSrcweir     msPaneURLPrefix + OUString::createFromAscii("LeftDrawPane"));
183*7a32b0c8SAndre Fischer const OUString FrameworkHelper::msSidebarPaneURL(
184*7a32b0c8SAndre Fischer     msPaneURLPrefix + OUString::createFromAscii("SidebarPane"));
185cdf0e10cSrcweir 
186cdf0e10cSrcweir 
187cdf0e10cSrcweir // View URLs.
188cdf0e10cSrcweir 
189cdf0e10cSrcweir const OUString FrameworkHelper::msViewURLPrefix(
190cdf0e10cSrcweir     OUString::createFromAscii("private:resource/view/"));
191cdf0e10cSrcweir const OUString FrameworkHelper::msImpressViewURL(
192cdf0e10cSrcweir     msViewURLPrefix + OUString::createFromAscii("ImpressView"));
193cdf0e10cSrcweir const OUString FrameworkHelper::msDrawViewURL(
194cdf0e10cSrcweir     msViewURLPrefix + OUString::createFromAscii("GraphicView"));
195cdf0e10cSrcweir const OUString FrameworkHelper::msOutlineViewURL(
196cdf0e10cSrcweir     msViewURLPrefix + OUString::createFromAscii("OutlineView"));
197cdf0e10cSrcweir const OUString FrameworkHelper::msNotesViewURL(
198cdf0e10cSrcweir     msViewURLPrefix + OUString::createFromAscii("NotesView"));
199cdf0e10cSrcweir const OUString FrameworkHelper::msHandoutViewURL(
200cdf0e10cSrcweir     msViewURLPrefix + OUString::createFromAscii("HandoutView"));
201cdf0e10cSrcweir const OUString FrameworkHelper::msSlideSorterURL(
202cdf0e10cSrcweir     msViewURLPrefix + OUString::createFromAscii("SlideSorter"));
203cdf0e10cSrcweir const OUString FrameworkHelper::msPresentationViewURL(
204cdf0e10cSrcweir     msViewURLPrefix + OUString::createFromAscii("PresentationView"));
205*7a32b0c8SAndre Fischer const OUString FrameworkHelper::msSidebarViewURL(
206*7a32b0c8SAndre Fischer     msViewURLPrefix + OUString::createFromAscii("SidebarView"));
207cdf0e10cSrcweir 
208cdf0e10cSrcweir 
209cdf0e10cSrcweir // Tool bar URLs.
210cdf0e10cSrcweir 
211cdf0e10cSrcweir const OUString FrameworkHelper::msToolBarURLPrefix(
212cdf0e10cSrcweir     OUString::createFromAscii("private:resource/toolbar/"));
213cdf0e10cSrcweir const OUString FrameworkHelper::msViewTabBarURL(
214cdf0e10cSrcweir     msToolBarURLPrefix + OUString::createFromAscii("ViewTabBar"));
215cdf0e10cSrcweir 
216cdf0e10cSrcweir 
217cdf0e10cSrcweir // Task panel URLs.
218cdf0e10cSrcweir const ::rtl::OUString FrameworkHelper::msTaskPanelURLPrefix(
219*7a32b0c8SAndre Fischer     OUString::createFromAscii("private:resource/toolpanel/"));
220*7a32b0c8SAndre Fischer const ::rtl::OUString FrameworkHelper::msAllMasterPagesTaskPanelURL(
221*7a32b0c8SAndre Fischer     msTaskPanelURLPrefix + OUString::createFromAscii("AllMasterPages"));
222*7a32b0c8SAndre Fischer const ::rtl::OUString FrameworkHelper::msRecentMasterPagesTaskPanelURL(
223*7a32b0c8SAndre Fischer     msTaskPanelURLPrefix + OUString::createFromAscii("RecentMasterPages"));
224*7a32b0c8SAndre Fischer const ::rtl::OUString FrameworkHelper::msUsedMasterPagesTaskPanelURL(
225*7a32b0c8SAndre Fischer     msTaskPanelURLPrefix + OUString::createFromAscii("UsedMasterPages"));
226cdf0e10cSrcweir const ::rtl::OUString FrameworkHelper::msLayoutTaskPanelURL(
227cdf0e10cSrcweir     msTaskPanelURLPrefix + OUString::createFromAscii("Layouts"));
228cdf0e10cSrcweir const ::rtl::OUString FrameworkHelper::msTableDesignPanelURL(
229cdf0e10cSrcweir     msTaskPanelURLPrefix + OUString::createFromAscii("TableDesign"));
230cdf0e10cSrcweir const ::rtl::OUString FrameworkHelper::msCustomAnimationTaskPanelURL(
231cdf0e10cSrcweir     msTaskPanelURLPrefix + OUString::createFromAscii("CustomAnimations"));
232cdf0e10cSrcweir const ::rtl::OUString FrameworkHelper::msSlideTransitionTaskPanelURL(
233cdf0e10cSrcweir     msTaskPanelURLPrefix + OUString::createFromAscii("SlideTransitions"));
234cdf0e10cSrcweir 
235cdf0e10cSrcweir 
236cdf0e10cSrcweir // Event URLs.
237cdf0e10cSrcweir const OUString FrameworkHelper::msResourceActivationRequestEvent(
238cdf0e10cSrcweir     OUString::createFromAscii("ResourceActivationRequested"));
239cdf0e10cSrcweir const OUString FrameworkHelper::msResourceDeactivationRequestEvent(
240cdf0e10cSrcweir     OUString::createFromAscii("ResourceDeactivationRequest"));
241cdf0e10cSrcweir const OUString FrameworkHelper::msResourceActivationEvent(
242cdf0e10cSrcweir     OUString::createFromAscii("ResourceActivation"));
243cdf0e10cSrcweir const OUString FrameworkHelper::msResourceDeactivationEvent(
244cdf0e10cSrcweir     OUString::createFromAscii("ResourceDeactivation"));
245*7a32b0c8SAndre Fischer const OUString FrameworkHelper::msResourceDeactivationEndEvent(
246*7a32b0c8SAndre Fischer     OUString::createFromAscii("ResourceDeactivationEnd"));
247cdf0e10cSrcweir const OUString FrameworkHelper::msConfigurationUpdateStartEvent(
248cdf0e10cSrcweir     OUString::createFromAscii("ConfigurationUpdateStart"));
249cdf0e10cSrcweir const OUString FrameworkHelper::msConfigurationUpdateEndEvent(
250cdf0e10cSrcweir     OUString::createFromAscii("ConfigurationUpdateEnd"));
251cdf0e10cSrcweir 
252cdf0e10cSrcweir 
253cdf0e10cSrcweir // Service names of controllers.
254cdf0e10cSrcweir const OUString FrameworkHelper::msModuleControllerService(
255cdf0e10cSrcweir     OUString::createFromAscii("com.sun.star.drawing.framework.ModuleController"));
256cdf0e10cSrcweir const OUString FrameworkHelper::msConfigurationControllerService(
257cdf0e10cSrcweir     OUString::createFromAscii("com.sun.star.drawing.framework.ConfigurationController"));
258cdf0e10cSrcweir 
259cdf0e10cSrcweir //----- helper ----------------------------------------------------------------
260cdf0e10cSrcweir namespace
261cdf0e10cSrcweir {
lcl_getViewShell(const Reference<XResource> & i_rViewShellWrapper)262cdf0e10cSrcweir     static ::boost::shared_ptr< ViewShell > lcl_getViewShell( const Reference< XResource >& i_rViewShellWrapper )
263cdf0e10cSrcweir     {
264cdf0e10cSrcweir         ::boost::shared_ptr< ViewShell > pViewShell;
265cdf0e10cSrcweir         if ( !i_rViewShellWrapper.is() )
266cdf0e10cSrcweir             return pViewShell;
267cdf0e10cSrcweir 
268cdf0e10cSrcweir         try
269cdf0e10cSrcweir         {
270cdf0e10cSrcweir             Reference<lang::XUnoTunnel> xViewTunnel( i_rViewShellWrapper, UNO_QUERY_THROW );
271cdf0e10cSrcweir             pViewShell = reinterpret_cast< ViewShellWrapper* >(
272cdf0e10cSrcweir                 xViewTunnel->getSomething( ViewShellWrapper::getUnoTunnelId() ) )->GetViewShell();
273cdf0e10cSrcweir         }
274cdf0e10cSrcweir         catch( const Exception& )
275cdf0e10cSrcweir         {
276cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
277cdf0e10cSrcweir         }
278cdf0e10cSrcweir         return pViewShell;
279cdf0e10cSrcweir     }
lcl_getFirstViewInPane(const Reference<XConfigurationController> & i_rConfigController,const Reference<XResourceId> & i_rPaneId)280cdf0e10cSrcweir     Reference< XResource > lcl_getFirstViewInPane( const Reference< XConfigurationController >& i_rConfigController,
281cdf0e10cSrcweir         const Reference< XResourceId >& i_rPaneId )
282cdf0e10cSrcweir     {
283cdf0e10cSrcweir         try
284cdf0e10cSrcweir         {
285cdf0e10cSrcweir             Reference< XConfiguration > xConfiguration( i_rConfigController->getRequestedConfiguration(), UNO_SET_THROW );
286cdf0e10cSrcweir             Sequence< Reference< XResourceId > > aViewIds( xConfiguration->getResources(
287cdf0e10cSrcweir                 i_rPaneId, FrameworkHelper::msViewURLPrefix, AnchorBindingMode_DIRECT ) );
288cdf0e10cSrcweir             if ( aViewIds.getLength() > 0 )
289cdf0e10cSrcweir                 return i_rConfigController->getResource( aViewIds[0] );
290cdf0e10cSrcweir         }
291cdf0e10cSrcweir         catch( const Exception& )
292cdf0e10cSrcweir         {
293cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
294cdf0e10cSrcweir         }
295cdf0e10cSrcweir         return NULL;
296cdf0e10cSrcweir     }
297cdf0e10cSrcweir }
298cdf0e10cSrcweir 
299cdf0e10cSrcweir 
300cdf0e10cSrcweir //----- FrameworkHelper::ViewURLMap -------------------------------------------
301cdf0e10cSrcweir 
302cdf0e10cSrcweir /** The ViewURLMap is used to translate between the view URLs used by the
303cdf0e10cSrcweir     drawing framework and the enums defined in the ViewShell class.
304cdf0e10cSrcweir */
305cdf0e10cSrcweir class FrameworkHelper::ViewURLMap
306cdf0e10cSrcweir     : public ::std::hash_map<
307cdf0e10cSrcweir           rtl::OUString,
308cdf0e10cSrcweir           ViewShell::ShellType,
309cdf0e10cSrcweir           ::comphelper::UStringHash,
310cdf0e10cSrcweir           ::comphelper::UStringEqual>
311cdf0e10cSrcweir {
312cdf0e10cSrcweir public:
ViewURLMap(void)313cdf0e10cSrcweir     ViewURLMap (void) {}
314cdf0e10cSrcweir };
315cdf0e10cSrcweir 
316cdf0e10cSrcweir 
317cdf0e10cSrcweir 
318cdf0e10cSrcweir 
319cdf0e10cSrcweir //----- Framework::DiposeListener ---------------------------------------------
320cdf0e10cSrcweir 
321cdf0e10cSrcweir namespace {
322cdf0e10cSrcweir     typedef ::cppu::WeakComponentImplHelper1 <
323cdf0e10cSrcweir         ::com::sun::star::lang::XEventListener
324cdf0e10cSrcweir         > FrameworkHelperDisposeListenerInterfaceBase;
325cdf0e10cSrcweir }
326cdf0e10cSrcweir 
327cdf0e10cSrcweir class FrameworkHelper::DisposeListener
328cdf0e10cSrcweir     : public ::sd::MutexOwner,
329cdf0e10cSrcweir       public FrameworkHelperDisposeListenerInterfaceBase
330cdf0e10cSrcweir {
331cdf0e10cSrcweir public:
332cdf0e10cSrcweir     DisposeListener (const ::boost::shared_ptr<FrameworkHelper>& rpHelper);
333cdf0e10cSrcweir     ~DisposeListener (void);
334cdf0e10cSrcweir 
335cdf0e10cSrcweir     virtual void SAL_CALL disposing (void);
336cdf0e10cSrcweir 
337cdf0e10cSrcweir     virtual void SAL_CALL disposing (const lang::EventObject& rEventObject)
338cdf0e10cSrcweir         throw(RuntimeException);
339cdf0e10cSrcweir 
340cdf0e10cSrcweir private:
341cdf0e10cSrcweir     ::boost::shared_ptr<FrameworkHelper> mpHelper;
342cdf0e10cSrcweir };
343cdf0e10cSrcweir 
344cdf0e10cSrcweir 
345cdf0e10cSrcweir 
346cdf0e10cSrcweir 
347*7a32b0c8SAndre Fischer //----- FrameworkHelper::Deleter ----------------------------------------------
348*7a32b0c8SAndre Fischer 
349*7a32b0c8SAndre Fischer class FrameworkHelper::Deleter
350*7a32b0c8SAndre Fischer {
351*7a32b0c8SAndre Fischer public:
operator ()(FrameworkHelper * pObject)352*7a32b0c8SAndre Fischer     void operator()(FrameworkHelper* pObject)
353*7a32b0c8SAndre Fischer     {
354*7a32b0c8SAndre Fischer         delete pObject;
355*7a32b0c8SAndre Fischer     }
356*7a32b0c8SAndre Fischer };
357*7a32b0c8SAndre Fischer 
358*7a32b0c8SAndre Fischer 
359*7a32b0c8SAndre Fischer 
360*7a32b0c8SAndre Fischer 
361cdf0e10cSrcweir //----- FrameworkHelper -------------------------------------------------------
362cdf0e10cSrcweir 
363cdf0e10cSrcweir ::boost::scoped_ptr<FrameworkHelper::ViewURLMap> FrameworkHelper::mpViewURLMap(new ViewURLMap());
364cdf0e10cSrcweir 
365cdf0e10cSrcweir 
366cdf0e10cSrcweir FrameworkHelper::InstanceMap FrameworkHelper::maInstanceMap;
367cdf0e10cSrcweir 
368cdf0e10cSrcweir 
369cdf0e10cSrcweir 
Instance(const Reference<frame::XController> & rxController)370cdf0e10cSrcweir ::boost::shared_ptr<FrameworkHelper> FrameworkHelper::Instance (
371cdf0e10cSrcweir     const Reference<frame::XController>& rxController)
372cdf0e10cSrcweir {
373cdf0e10cSrcweir     // Tunnel through the controller to obtain a ViewShellBase.
374cdf0e10cSrcweir     Reference<lang::XUnoTunnel> xTunnel (rxController, UNO_QUERY);
375cdf0e10cSrcweir     if (xTunnel.is())
376cdf0e10cSrcweir     {
377cdf0e10cSrcweir         ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>(
378cdf0e10cSrcweir             xTunnel->getSomething(sd::DrawController::getUnoTunnelId()));
379cdf0e10cSrcweir         if (pController != NULL)
380cdf0e10cSrcweir         {
381cdf0e10cSrcweir             ViewShellBase* pBase = pController->GetViewShellBase();
382cdf0e10cSrcweir             if (pBase != NULL)
383cdf0e10cSrcweir                 return Instance(*pBase);
384cdf0e10cSrcweir         }
385cdf0e10cSrcweir     }
386cdf0e10cSrcweir 
387cdf0e10cSrcweir     return ::boost::shared_ptr<FrameworkHelper>();
388cdf0e10cSrcweir }
389cdf0e10cSrcweir 
390cdf0e10cSrcweir 
391cdf0e10cSrcweir 
392cdf0e10cSrcweir 
Instance(ViewShellBase & rBase)393cdf0e10cSrcweir ::boost::shared_ptr<FrameworkHelper> FrameworkHelper::Instance (ViewShellBase& rBase)
394cdf0e10cSrcweir {
395cdf0e10cSrcweir 
396cdf0e10cSrcweir     ::boost::shared_ptr<FrameworkHelper> pHelper;
397cdf0e10cSrcweir 
398cdf0e10cSrcweir     InstanceMap::const_iterator iHelper (maInstanceMap.find(&rBase));
399cdf0e10cSrcweir     if (iHelper == maInstanceMap.end())
400cdf0e10cSrcweir     {
401cdf0e10cSrcweir         ::osl::GetGlobalMutex aMutexFunctor;
402cdf0e10cSrcweir         ::osl::MutexGuard aGuard (aMutexFunctor());
403cdf0e10cSrcweir         if (iHelper == maInstanceMap.end())
404cdf0e10cSrcweir         {
405*7a32b0c8SAndre Fischer             pHelper = ::boost::shared_ptr<FrameworkHelper>(
406*7a32b0c8SAndre Fischer                 new FrameworkHelper(rBase),
407*7a32b0c8SAndre Fischer                 FrameworkHelper::Deleter());
408cdf0e10cSrcweir             pHelper->Initialize();
409cdf0e10cSrcweir             OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
410cdf0e10cSrcweir             maInstanceMap[&rBase] = pHelper;
411cdf0e10cSrcweir         }
412cdf0e10cSrcweir     }
413cdf0e10cSrcweir     else
414cdf0e10cSrcweir     {
415cdf0e10cSrcweir         OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
416cdf0e10cSrcweir         pHelper = iHelper->second;
417cdf0e10cSrcweir     }
418cdf0e10cSrcweir 
419cdf0e10cSrcweir     return pHelper;
420cdf0e10cSrcweir }
421cdf0e10cSrcweir 
422cdf0e10cSrcweir 
423cdf0e10cSrcweir 
424cdf0e10cSrcweir 
DisposeInstance(ViewShellBase & rBase)425cdf0e10cSrcweir void FrameworkHelper::DisposeInstance (ViewShellBase& rBase)
426cdf0e10cSrcweir {
427cdf0e10cSrcweir     InstanceMap::iterator iHelper (maInstanceMap.find(&rBase));
428cdf0e10cSrcweir     if (iHelper != maInstanceMap.end())
429cdf0e10cSrcweir     {
430cdf0e10cSrcweir         iHelper->second->Dispose();
431cdf0e10cSrcweir     }
432cdf0e10cSrcweir }
433cdf0e10cSrcweir 
434cdf0e10cSrcweir 
435cdf0e10cSrcweir 
436cdf0e10cSrcweir 
ReleaseInstance(ViewShellBase & rBase)437cdf0e10cSrcweir void FrameworkHelper::ReleaseInstance (ViewShellBase& rBase)
438cdf0e10cSrcweir {
439cdf0e10cSrcweir     InstanceMap::iterator iHelper (maInstanceMap.find(&rBase));
440cdf0e10cSrcweir     if (iHelper != maInstanceMap.end())
441cdf0e10cSrcweir         maInstanceMap.erase(iHelper);
442cdf0e10cSrcweir }
443cdf0e10cSrcweir 
444cdf0e10cSrcweir 
445cdf0e10cSrcweir 
446cdf0e10cSrcweir 
FrameworkHelper(ViewShellBase & rBase)447cdf0e10cSrcweir FrameworkHelper::FrameworkHelper (ViewShellBase& rBase)
448cdf0e10cSrcweir     : mrBase(rBase),
449cdf0e10cSrcweir       mxConfigurationController(),
450cdf0e10cSrcweir       mxDisposeListener()
451cdf0e10cSrcweir 
452cdf0e10cSrcweir {
453cdf0e10cSrcweir     Reference<XControllerManager> xControllerManager (rBase.GetController(), UNO_QUERY);
454cdf0e10cSrcweir     if (xControllerManager.is())
455cdf0e10cSrcweir     {
456cdf0e10cSrcweir         mxConfigurationController = xControllerManager->getConfigurationController();
457cdf0e10cSrcweir     }
458cdf0e10cSrcweir 
459cdf0e10cSrcweir     new LifetimeController(mrBase);
460cdf0e10cSrcweir }
461cdf0e10cSrcweir 
462cdf0e10cSrcweir 
463cdf0e10cSrcweir 
464cdf0e10cSrcweir 
Initialize(void)465cdf0e10cSrcweir void FrameworkHelper::Initialize (void)
466cdf0e10cSrcweir {
467cdf0e10cSrcweir     mxDisposeListener = new DisposeListener(shared_from_this());
468cdf0e10cSrcweir }
469cdf0e10cSrcweir 
470cdf0e10cSrcweir 
471cdf0e10cSrcweir 
472cdf0e10cSrcweir 
~FrameworkHelper(void)473cdf0e10cSrcweir FrameworkHelper::~FrameworkHelper (void)
474cdf0e10cSrcweir {
475cdf0e10cSrcweir }
476cdf0e10cSrcweir 
477cdf0e10cSrcweir 
478cdf0e10cSrcweir 
479cdf0e10cSrcweir 
Dispose(void)480cdf0e10cSrcweir void FrameworkHelper::Dispose (void)
481cdf0e10cSrcweir {
482cdf0e10cSrcweir     if (mxDisposeListener.is())
483cdf0e10cSrcweir         mxDisposeListener->dispose();
484cdf0e10cSrcweir     mxConfigurationController = NULL;
485cdf0e10cSrcweir }
486cdf0e10cSrcweir 
487cdf0e10cSrcweir 
488cdf0e10cSrcweir 
489cdf0e10cSrcweir 
IsValid(void)490cdf0e10cSrcweir bool FrameworkHelper::IsValid (void)
491cdf0e10cSrcweir {
492cdf0e10cSrcweir     return mxConfigurationController.is();
493cdf0e10cSrcweir }
494cdf0e10cSrcweir 
495cdf0e10cSrcweir 
496cdf0e10cSrcweir 
497cdf0e10cSrcweir 
GetViewShell(const OUString & rsPaneURL)498cdf0e10cSrcweir ::boost::shared_ptr<ViewShell> FrameworkHelper::GetViewShell (const OUString& rsPaneURL)
499cdf0e10cSrcweir {
500cdf0e10cSrcweir     if ( !mxConfigurationController.is() )
501cdf0e10cSrcweir         return ::boost::shared_ptr<ViewShell>();
502cdf0e10cSrcweir 
503cdf0e10cSrcweir     Reference<XResourceId> xPaneId( CreateResourceId( rsPaneURL ) );
504cdf0e10cSrcweir     return lcl_getViewShell( lcl_getFirstViewInPane( mxConfigurationController, xPaneId ) );
505cdf0e10cSrcweir }
506cdf0e10cSrcweir 
507cdf0e10cSrcweir 
508cdf0e10cSrcweir 
509cdf0e10cSrcweir 
GetViewShell(const Reference<XView> & rxView)510cdf0e10cSrcweir ::boost::shared_ptr<ViewShell> FrameworkHelper::GetViewShell (const Reference<XView>& rxView)
511cdf0e10cSrcweir {
512cdf0e10cSrcweir     return lcl_getViewShell( rxView.get() );
513cdf0e10cSrcweir }
514cdf0e10cSrcweir 
515cdf0e10cSrcweir 
516cdf0e10cSrcweir 
517cdf0e10cSrcweir 
GetView(const Reference<XResourceId> & rxPaneOrViewId)518cdf0e10cSrcweir Reference<XView> FrameworkHelper::GetView (const Reference<XResourceId>& rxPaneOrViewId)
519cdf0e10cSrcweir {
520cdf0e10cSrcweir     Reference<XView> xView;
521cdf0e10cSrcweir 
522cdf0e10cSrcweir     if ( ! rxPaneOrViewId.is() || ! mxConfigurationController.is())
523cdf0e10cSrcweir         return NULL;
524cdf0e10cSrcweir 
525cdf0e10cSrcweir     try
526cdf0e10cSrcweir     {
527cdf0e10cSrcweir         if (rxPaneOrViewId->getResourceURL().match(msViewURLPrefix))
528cdf0e10cSrcweir         {
529cdf0e10cSrcweir             xView.set( mxConfigurationController->getResource( rxPaneOrViewId ), UNO_QUERY );
530cdf0e10cSrcweir         }
531cdf0e10cSrcweir         else
532cdf0e10cSrcweir         {
533cdf0e10cSrcweir             xView.set( lcl_getFirstViewInPane( mxConfigurationController, rxPaneOrViewId ), UNO_QUERY );
534cdf0e10cSrcweir         }
535cdf0e10cSrcweir     }
536cdf0e10cSrcweir     catch (lang::DisposedException&)
537cdf0e10cSrcweir     {
538cdf0e10cSrcweir         Dispose();
539cdf0e10cSrcweir     }
540cdf0e10cSrcweir     catch (RuntimeException&)
541cdf0e10cSrcweir     {
542cdf0e10cSrcweir     }
543cdf0e10cSrcweir 
544cdf0e10cSrcweir     return xView;
545cdf0e10cSrcweir }
546cdf0e10cSrcweir 
547cdf0e10cSrcweir 
548cdf0e10cSrcweir 
549cdf0e10cSrcweir 
GetPaneWindow(const Reference<XResourceId> & rxPaneId)550*7a32b0c8SAndre Fischer Reference<awt::XWindow> FrameworkHelper::GetPaneWindow (const Reference<XResourceId>& rxPaneId)
551*7a32b0c8SAndre Fischer {
552*7a32b0c8SAndre Fischer     Reference<awt::XWindow> xWindow;
553*7a32b0c8SAndre Fischer 
554*7a32b0c8SAndre Fischer     if (rxPaneId.is() && mxConfigurationController.is())
555*7a32b0c8SAndre Fischer     {
556*7a32b0c8SAndre Fischer         try
557*7a32b0c8SAndre Fischer         {
558*7a32b0c8SAndre Fischer             if (rxPaneId->getResourceURL().match(msPaneURLPrefix))
559*7a32b0c8SAndre Fischer             {
560*7a32b0c8SAndre Fischer                 Reference<XPane> xPane (mxConfigurationController->getResource(rxPaneId), UNO_QUERY);
561*7a32b0c8SAndre Fischer                 if (xPane.is())
562*7a32b0c8SAndre Fischer                     xWindow = xPane->getWindow();
563*7a32b0c8SAndre Fischer             }
564*7a32b0c8SAndre Fischer         }
565*7a32b0c8SAndre Fischer         catch (lang::DisposedException&)
566*7a32b0c8SAndre Fischer         {
567*7a32b0c8SAndre Fischer             Dispose();
568*7a32b0c8SAndre Fischer         }
569*7a32b0c8SAndre Fischer         catch (RuntimeException&)
570*7a32b0c8SAndre Fischer         {
571*7a32b0c8SAndre Fischer         }
572*7a32b0c8SAndre Fischer     }
573*7a32b0c8SAndre Fischer 
574*7a32b0c8SAndre Fischer     return xWindow;
575*7a32b0c8SAndre Fischer }
576*7a32b0c8SAndre Fischer 
577*7a32b0c8SAndre Fischer 
578*7a32b0c8SAndre Fischer 
579*7a32b0c8SAndre Fischer 
GetResource(const Reference<XResourceId> & rxResourceId)580*7a32b0c8SAndre Fischer Reference<XResource> FrameworkHelper::GetResource (const Reference<XResourceId>& rxResourceId)
581*7a32b0c8SAndre Fischer {
582*7a32b0c8SAndre Fischer     Reference<XResource> xResource;
583*7a32b0c8SAndre Fischer 
584*7a32b0c8SAndre Fischer     if (rxResourceId.is() && mxConfigurationController.is())
585*7a32b0c8SAndre Fischer     {
586*7a32b0c8SAndre Fischer         try
587*7a32b0c8SAndre Fischer         {
588*7a32b0c8SAndre Fischer             return mxConfigurationController->getResource(rxResourceId);
589*7a32b0c8SAndre Fischer         }
590*7a32b0c8SAndre Fischer         catch (lang::DisposedException&)
591*7a32b0c8SAndre Fischer         {
592*7a32b0c8SAndre Fischer             Dispose();
593*7a32b0c8SAndre Fischer         }
594*7a32b0c8SAndre Fischer         catch (RuntimeException&)
595*7a32b0c8SAndre Fischer         {
596*7a32b0c8SAndre Fischer         }
597*7a32b0c8SAndre Fischer     }
598*7a32b0c8SAndre Fischer 
599*7a32b0c8SAndre Fischer     return NULL;
600*7a32b0c8SAndre Fischer }
601*7a32b0c8SAndre Fischer 
602*7a32b0c8SAndre Fischer 
603*7a32b0c8SAndre Fischer 
604*7a32b0c8SAndre Fischer 
RequestView(const OUString & rsResourceURL,const OUString & rsAnchorURL)605cdf0e10cSrcweir Reference<XResourceId> FrameworkHelper::RequestView (
606cdf0e10cSrcweir     const OUString& rsResourceURL,
607cdf0e10cSrcweir     const OUString& rsAnchorURL)
608cdf0e10cSrcweir {
609cdf0e10cSrcweir     Reference<XResourceId> xViewId;
610cdf0e10cSrcweir 
611cdf0e10cSrcweir     try
612cdf0e10cSrcweir     {
613cdf0e10cSrcweir         if (mxConfigurationController.is())
614cdf0e10cSrcweir         {
615cdf0e10cSrcweir             mxConfigurationController->requestResourceActivation(
616cdf0e10cSrcweir                 CreateResourceId(rsAnchorURL),
617cdf0e10cSrcweir                 ResourceActivationMode_ADD);
618cdf0e10cSrcweir             xViewId = CreateResourceId(rsResourceURL, rsAnchorURL);
619cdf0e10cSrcweir             mxConfigurationController->requestResourceActivation(
620cdf0e10cSrcweir                 xViewId,
621cdf0e10cSrcweir                 ResourceActivationMode_REPLACE);
622cdf0e10cSrcweir         }
623cdf0e10cSrcweir     }
624cdf0e10cSrcweir     catch (lang::DisposedException&)
625cdf0e10cSrcweir     {
626cdf0e10cSrcweir         Dispose();
627cdf0e10cSrcweir         xViewId = NULL;
628cdf0e10cSrcweir     }
629cdf0e10cSrcweir     catch (RuntimeException&)
630cdf0e10cSrcweir     {
631cdf0e10cSrcweir         xViewId = NULL;
632cdf0e10cSrcweir     }
633cdf0e10cSrcweir 
634cdf0e10cSrcweir     return xViewId;
635cdf0e10cSrcweir }
636cdf0e10cSrcweir 
637cdf0e10cSrcweir 
638cdf0e10cSrcweir 
639cdf0e10cSrcweir 
RequestResourceDeactivation(const cssu::Reference<cssdf::XResourceId> & rxResourceId)640*7a32b0c8SAndre Fischer void FrameworkHelper::RequestResourceDeactivation (const cssu::Reference<cssdf::XResourceId>& rxResourceId)
641*7a32b0c8SAndre Fischer {
642*7a32b0c8SAndre Fischer     try
643*7a32b0c8SAndre Fischer     {
644*7a32b0c8SAndre Fischer         if (mxConfigurationController.is() && rxResourceId.is())
645*7a32b0c8SAndre Fischer             mxConfigurationController->requestResourceDeactivation(rxResourceId);
646*7a32b0c8SAndre Fischer     }
647*7a32b0c8SAndre Fischer     catch (lang::DisposedException&)
648*7a32b0c8SAndre Fischer     {
649*7a32b0c8SAndre Fischer         Dispose();
650*7a32b0c8SAndre Fischer     }
651*7a32b0c8SAndre Fischer     catch (RuntimeException&)
652*7a32b0c8SAndre Fischer     {}
653cdf0e10cSrcweir }
654cdf0e10cSrcweir 
655cdf0e10cSrcweir 
656cdf0e10cSrcweir 
657cdf0e10cSrcweir 
GetViewId(const rtl::OUString & rsViewURL)658cdf0e10cSrcweir ViewShell::ShellType FrameworkHelper::GetViewId (const rtl::OUString& rsViewURL)
659cdf0e10cSrcweir {
660cdf0e10cSrcweir     if (mpViewURLMap->empty())
661cdf0e10cSrcweir     {
662cdf0e10cSrcweir         (*mpViewURLMap)[msImpressViewURL] = ViewShell::ST_IMPRESS;
663cdf0e10cSrcweir         (*mpViewURLMap)[msDrawViewURL] = ViewShell::ST_DRAW;
664cdf0e10cSrcweir         (*mpViewURLMap)[msOutlineViewURL] = ViewShell::ST_OUTLINE;
665cdf0e10cSrcweir         (*mpViewURLMap)[msNotesViewURL] = ViewShell::ST_NOTES;
666cdf0e10cSrcweir         (*mpViewURLMap)[msHandoutViewURL] = ViewShell::ST_HANDOUT;
667cdf0e10cSrcweir         (*mpViewURLMap)[msSlideSorterURL] = ViewShell::ST_SLIDE_SORTER;
668cdf0e10cSrcweir         (*mpViewURLMap)[msPresentationViewURL] = ViewShell::ST_PRESENTATION;
669*7a32b0c8SAndre Fischer         (*mpViewURLMap)[msSidebarViewURL] = ViewShell::ST_SIDEBAR;
670cdf0e10cSrcweir     }
671cdf0e10cSrcweir     ViewURLMap::const_iterator iView (mpViewURLMap->find(rsViewURL));
672cdf0e10cSrcweir     if (iView != mpViewURLMap->end())
673cdf0e10cSrcweir         return iView->second;
674cdf0e10cSrcweir     else
675cdf0e10cSrcweir         return ViewShell::ST_NONE;
676cdf0e10cSrcweir }
677cdf0e10cSrcweir 
678cdf0e10cSrcweir 
679cdf0e10cSrcweir 
680cdf0e10cSrcweir 
GetViewURL(ViewShell::ShellType eType)681cdf0e10cSrcweir ::rtl::OUString FrameworkHelper::GetViewURL (ViewShell::ShellType eType)
682cdf0e10cSrcweir {
683cdf0e10cSrcweir     switch (eType)
684cdf0e10cSrcweir     {
685cdf0e10cSrcweir         case ViewShell::ST_IMPRESS : return msImpressViewURL;
686cdf0e10cSrcweir         case ViewShell::ST_DRAW : return msDrawViewURL;
687cdf0e10cSrcweir         case ViewShell::ST_OUTLINE : return msOutlineViewURL;
688cdf0e10cSrcweir         case ViewShell::ST_NOTES : return msNotesViewURL;
689cdf0e10cSrcweir         case ViewShell::ST_HANDOUT : return msHandoutViewURL;
690cdf0e10cSrcweir         case ViewShell::ST_SLIDE_SORTER : return msSlideSorterURL;
691cdf0e10cSrcweir         case ViewShell::ST_PRESENTATION : return msPresentationViewURL;
692*7a32b0c8SAndre Fischer         case ViewShell::ST_SIDEBAR : return msSidebarViewURL;
693cdf0e10cSrcweir         default:
694cdf0e10cSrcweir             return OUString();
695cdf0e10cSrcweir     }
696cdf0e10cSrcweir }
697cdf0e10cSrcweir 
698cdf0e10cSrcweir 
699cdf0e10cSrcweir 
700cdf0e10cSrcweir 
HandleModeChangeSlot(sal_uLong nSlotId,SfxRequest & rRequest)701cdf0e10cSrcweir void FrameworkHelper::HandleModeChangeSlot (
702cdf0e10cSrcweir     sal_uLong nSlotId,
703cdf0e10cSrcweir     SfxRequest& rRequest)
704cdf0e10cSrcweir {
705cdf0e10cSrcweir     sal_Bool bIsActive = sal_True;
706cdf0e10cSrcweir 
707cdf0e10cSrcweir     if ( ! mxConfigurationController.is())
708cdf0e10cSrcweir         return;
709cdf0e10cSrcweir 
710cdf0e10cSrcweir     switch (nSlotId)
711cdf0e10cSrcweir     {
712cdf0e10cSrcweir         case SID_DRAWINGMODE:
713cdf0e10cSrcweir         case SID_NOTESMODE:
714cdf0e10cSrcweir 		case SID_HANDOUTMODE:
715cdf0e10cSrcweir 		case SID_DIAMODE:
716cdf0e10cSrcweir 		case SID_OUTLINEMODE:
717cdf0e10cSrcweir         {
718cdf0e10cSrcweir 			const SfxItemSet* pRequestArguments = rRequest.GetArgs();
719cdf0e10cSrcweir 			if (pRequestArguments)
720cdf0e10cSrcweir             {
721cdf0e10cSrcweir                 SFX_REQUEST_ARG (rRequest,
722cdf0e10cSrcweir                     pIsActive,
723cdf0e10cSrcweir                     SfxBoolItem,
724cdf0e10cSrcweir                     (sal_uInt16)nSlotId,
725cdf0e10cSrcweir                     sal_False);
726cdf0e10cSrcweir 				bIsActive = pIsActive->GetValue ();
727cdf0e10cSrcweir 			}
728cdf0e10cSrcweir         }
729cdf0e10cSrcweir         break;
730cdf0e10cSrcweir     }
731cdf0e10cSrcweir 
732cdf0e10cSrcweir     try
733cdf0e10cSrcweir     {
734cdf0e10cSrcweir         if ( ! mxConfigurationController.is())
735cdf0e10cSrcweir             throw RuntimeException();
736cdf0e10cSrcweir 
737cdf0e10cSrcweir 
738cdf0e10cSrcweir         Reference<XResourceId> xPaneId (
739cdf0e10cSrcweir             CreateResourceId(framework::FrameworkHelper::msCenterPaneURL));
740cdf0e10cSrcweir         Reference<XView> xView (GetView(xPaneId));
741cdf0e10cSrcweir         ::boost::shared_ptr<ViewShell> pCenterViewShell (GetViewShell(xView));
742cdf0e10cSrcweir 
743cdf0e10cSrcweir         ::rtl::OUString sRequestedView;
744cdf0e10cSrcweir         if (bIsActive)
745cdf0e10cSrcweir         {
746cdf0e10cSrcweir             switch (nSlotId)
747cdf0e10cSrcweir             {
748cdf0e10cSrcweir                 case SID_NORMAL_MULTI_PANE_GUI:
749cdf0e10cSrcweir                 case SID_DRAWINGMODE:
750cdf0e10cSrcweir                     sRequestedView = FrameworkHelper::msImpressViewURL;
751cdf0e10cSrcweir                     break;
752cdf0e10cSrcweir 
753cdf0e10cSrcweir                 case SID_NOTESMODE:
754cdf0e10cSrcweir                     sRequestedView = FrameworkHelper::msNotesViewURL;
755cdf0e10cSrcweir                 break;
756cdf0e10cSrcweir 
757cdf0e10cSrcweir                 case SID_HANDOUTMODE:
758cdf0e10cSrcweir                     sRequestedView = FrameworkHelper::msHandoutViewURL;
759cdf0e10cSrcweir                     break;
760cdf0e10cSrcweir 
761cdf0e10cSrcweir                 case SID_SLIDE_SORTER_MULTI_PANE_GUI:
762cdf0e10cSrcweir                 case SID_DIAMODE:
763cdf0e10cSrcweir                     sRequestedView = FrameworkHelper::msSlideSorterURL;
764cdf0e10cSrcweir                     break;
765cdf0e10cSrcweir 
766cdf0e10cSrcweir                 case SID_OUTLINEMODE:
767cdf0e10cSrcweir                     sRequestedView = FrameworkHelper::msOutlineViewURL;
768cdf0e10cSrcweir                     break;
769cdf0e10cSrcweir             }
770cdf0e10cSrcweir         }
771cdf0e10cSrcweir 
772cdf0e10cSrcweir         if (xView.is()
773cdf0e10cSrcweir             && xView->getResourceId()->getResourceURL().equals(sRequestedView))
774cdf0e10cSrcweir         {
775cdf0e10cSrcweir             // We do not have to switch the view shell but maybe the edit mode
776cdf0e10cSrcweir             // has changed.
777cdf0e10cSrcweir             DrawViewShell* pDrawViewShell
778cdf0e10cSrcweir                 = dynamic_cast<DrawViewShell*>(pCenterViewShell.get());
779cdf0e10cSrcweir             if (pDrawViewShell != NULL)
780cdf0e10cSrcweir             {
781cdf0e10cSrcweir                 pCenterViewShell->Broadcast (
782cdf0e10cSrcweir                     ViewShellHint(ViewShellHint::HINT_CHANGE_EDIT_MODE_START));
783cdf0e10cSrcweir 
784cdf0e10cSrcweir                 pDrawViewShell->ChangeEditMode (
785cdf0e10cSrcweir                     EM_PAGE, pDrawViewShell->IsLayerModeActive());
786cdf0e10cSrcweir 
787cdf0e10cSrcweir                 pCenterViewShell->Broadcast (
788cdf0e10cSrcweir                     ViewShellHint(ViewShellHint::HINT_CHANGE_EDIT_MODE_END));
789cdf0e10cSrcweir             }
790cdf0e10cSrcweir         }
791cdf0e10cSrcweir         else
792cdf0e10cSrcweir         {
793cdf0e10cSrcweir             mxConfigurationController->requestResourceActivation(
794cdf0e10cSrcweir                 CreateResourceId(sRequestedView, msCenterPaneURL),
795cdf0e10cSrcweir                 ResourceActivationMode_REPLACE);
796cdf0e10cSrcweir         }
797cdf0e10cSrcweir     }
798cdf0e10cSrcweir     catch (RuntimeException&)
799cdf0e10cSrcweir     {
800cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
801cdf0e10cSrcweir     }
802cdf0e10cSrcweir }
803cdf0e10cSrcweir 
804cdf0e10cSrcweir 
805cdf0e10cSrcweir 
806cdf0e10cSrcweir 
RunOnConfigurationEvent(const::rtl::OUString & rsEventType,const Callback & rCallback)807cdf0e10cSrcweir void FrameworkHelper::RunOnConfigurationEvent(
808cdf0e10cSrcweir     const ::rtl::OUString& rsEventType,
809cdf0e10cSrcweir     const Callback& rCallback)
810cdf0e10cSrcweir {
811cdf0e10cSrcweir     RunOnEvent(
812cdf0e10cSrcweir         rsEventType,
813cdf0e10cSrcweir         FrameworkHelperAllPassFilter(),
814cdf0e10cSrcweir         rCallback);
815cdf0e10cSrcweir }
816cdf0e10cSrcweir 
817cdf0e10cSrcweir 
818cdf0e10cSrcweir 
819cdf0e10cSrcweir 
RunOnResourceActivation(const css::uno::Reference<css::drawing::framework::XResourceId> & rxResourceId,const Callback & rCallback)820cdf0e10cSrcweir void FrameworkHelper::RunOnResourceActivation(
821cdf0e10cSrcweir     const css::uno::Reference<css::drawing::framework::XResourceId>& rxResourceId,
822cdf0e10cSrcweir     const Callback& rCallback)
823cdf0e10cSrcweir {
824cdf0e10cSrcweir     if (mxConfigurationController.is()
825cdf0e10cSrcweir         && mxConfigurationController->getResource(rxResourceId).is())
826cdf0e10cSrcweir     {
827cdf0e10cSrcweir         rCallback(false);
828cdf0e10cSrcweir     }
829cdf0e10cSrcweir     else
830cdf0e10cSrcweir     {
831cdf0e10cSrcweir         RunOnEvent(
832cdf0e10cSrcweir             msResourceActivationEvent,
833cdf0e10cSrcweir             FrameworkHelperResourceIdFilter(rxResourceId),
834cdf0e10cSrcweir             rCallback);
835cdf0e10cSrcweir     }
836cdf0e10cSrcweir }
837cdf0e10cSrcweir 
838cdf0e10cSrcweir 
839cdf0e10cSrcweir 
840cdf0e10cSrcweir 
RunOnResourceDeactivation(const css::uno::Reference<css::drawing::framework::XResourceId> & rxResourceId,const Callback & rCallback,const bool bRunOnDeactivationEnd)841*7a32b0c8SAndre Fischer void FrameworkHelper::RunOnResourceDeactivation(
842*7a32b0c8SAndre Fischer     const css::uno::Reference<css::drawing::framework::XResourceId>& rxResourceId,
843*7a32b0c8SAndre Fischer     const Callback& rCallback,
844*7a32b0c8SAndre Fischer     const bool bRunOnDeactivationEnd)
845*7a32b0c8SAndre Fischer {
846*7a32b0c8SAndre Fischer     if (mxConfigurationController.is()
847*7a32b0c8SAndre Fischer         && ! mxConfigurationController->getResource(rxResourceId).is())
848*7a32b0c8SAndre Fischer     {
849*7a32b0c8SAndre Fischer         rCallback(false);
850*7a32b0c8SAndre Fischer     }
851*7a32b0c8SAndre Fischer     else
852*7a32b0c8SAndre Fischer     {
853*7a32b0c8SAndre Fischer         RunOnEvent(
854*7a32b0c8SAndre Fischer             bRunOnDeactivationEnd
855*7a32b0c8SAndre Fischer                 ? msResourceDeactivationEndEvent
856*7a32b0c8SAndre Fischer                 : msResourceDeactivationEvent,
857*7a32b0c8SAndre Fischer             FrameworkHelperResourceIdFilter(rxResourceId),
858*7a32b0c8SAndre Fischer             rCallback);
859*7a32b0c8SAndre Fischer     }
860*7a32b0c8SAndre Fischer }
861*7a32b0c8SAndre Fischer 
862*7a32b0c8SAndre Fischer 
863*7a32b0c8SAndre Fischer 
864*7a32b0c8SAndre Fischer 
865cdf0e10cSrcweir /** A callback that sets a flag to a specified value when the callback is
866cdf0e10cSrcweir     called.
867cdf0e10cSrcweir */
868cdf0e10cSrcweir class FlagUpdater
869cdf0e10cSrcweir {
870cdf0e10cSrcweir public:
FlagUpdater(bool & rFlag)871cdf0e10cSrcweir     FlagUpdater (bool& rFlag) : mrFlag(rFlag) {}
operator ()(bool)872cdf0e10cSrcweir     void operator() (bool) {mrFlag = true;}
873cdf0e10cSrcweir private:
874cdf0e10cSrcweir     bool& mrFlag;
875cdf0e10cSrcweir };
876cdf0e10cSrcweir 
877cdf0e10cSrcweir 
878cdf0e10cSrcweir 
879cdf0e10cSrcweir 
RequestSynchronousUpdate(void)880cdf0e10cSrcweir void FrameworkHelper::RequestSynchronousUpdate (void)
881cdf0e10cSrcweir {
882cdf0e10cSrcweir     rtl::Reference<ConfigurationController> pCC (
883cdf0e10cSrcweir         dynamic_cast<ConfigurationController*>(mxConfigurationController.get()));
884cdf0e10cSrcweir     if (pCC.is())
885cdf0e10cSrcweir         pCC->RequestSynchronousUpdate();
886cdf0e10cSrcweir }
887cdf0e10cSrcweir 
888cdf0e10cSrcweir 
889cdf0e10cSrcweir 
890cdf0e10cSrcweir 
WaitForEvent(const OUString & rsEventType) const891cdf0e10cSrcweir void FrameworkHelper::WaitForEvent (const OUString& rsEventType) const
892cdf0e10cSrcweir {
893cdf0e10cSrcweir     bool bConfigurationUpdateSeen (false);
894cdf0e10cSrcweir 
895cdf0e10cSrcweir     RunOnEvent(
896cdf0e10cSrcweir         rsEventType,
897cdf0e10cSrcweir         FrameworkHelperAllPassFilter(),
898cdf0e10cSrcweir         FlagUpdater(bConfigurationUpdateSeen));
899cdf0e10cSrcweir 
900cdf0e10cSrcweir 	sal_uInt32 nStartTime = osl_getGlobalTimer();
901cdf0e10cSrcweir     while ( ! bConfigurationUpdateSeen)
902cdf0e10cSrcweir     {
903cdf0e10cSrcweir         Application::Reschedule();
904cdf0e10cSrcweir 
905cdf0e10cSrcweir 		if( (osl_getGlobalTimer() - nStartTime) > 60000  )
906cdf0e10cSrcweir 		{
907cdf0e10cSrcweir 			DBG_ERROR("FrameworkHelper::WaitForEvent(), no event for a minute? giving up!");
908cdf0e10cSrcweir 			break;
909cdf0e10cSrcweir 		}
910cdf0e10cSrcweir     }
911cdf0e10cSrcweir }
912cdf0e10cSrcweir 
913cdf0e10cSrcweir 
914cdf0e10cSrcweir 
915cdf0e10cSrcweir 
WaitForUpdate(void) const916cdf0e10cSrcweir void FrameworkHelper::WaitForUpdate (void) const
917cdf0e10cSrcweir {
918cdf0e10cSrcweir     WaitForEvent(msConfigurationUpdateEndEvent);
919cdf0e10cSrcweir }
920cdf0e10cSrcweir 
921cdf0e10cSrcweir 
922cdf0e10cSrcweir 
923cdf0e10cSrcweir 
RunOnEvent(const::rtl::OUString & rsEventType,const ConfigurationChangeEventFilter & rFilter,const Callback & rCallback) const924cdf0e10cSrcweir void FrameworkHelper::RunOnEvent(
925cdf0e10cSrcweir     const ::rtl::OUString& rsEventType,
926cdf0e10cSrcweir     const ConfigurationChangeEventFilter& rFilter,
927cdf0e10cSrcweir     const Callback& rCallback) const
928cdf0e10cSrcweir {
929cdf0e10cSrcweir     new CallbackCaller(mrBase,rsEventType,rFilter,rCallback);
930cdf0e10cSrcweir }
931cdf0e10cSrcweir 
932cdf0e10cSrcweir 
933cdf0e10cSrcweir 
934cdf0e10cSrcweir 
disposing(const lang::EventObject & rEventObject)935cdf0e10cSrcweir void FrameworkHelper::disposing (const lang::EventObject& rEventObject)
936cdf0e10cSrcweir {
937cdf0e10cSrcweir     if (rEventObject.Source == mxConfigurationController)
938cdf0e10cSrcweir         mxConfigurationController = NULL;
939cdf0e10cSrcweir }
940cdf0e10cSrcweir 
941cdf0e10cSrcweir 
942cdf0e10cSrcweir 
943cdf0e10cSrcweir 
UpdateConfiguration(void)944cdf0e10cSrcweir void FrameworkHelper::UpdateConfiguration (void)
945cdf0e10cSrcweir {
946cdf0e10cSrcweir     if (mxConfigurationController.is())
947cdf0e10cSrcweir     {
948cdf0e10cSrcweir         try
949cdf0e10cSrcweir         {
950cdf0e10cSrcweir             if (mxConfigurationController.is())
951cdf0e10cSrcweir                 mxConfigurationController->update();
952cdf0e10cSrcweir         }
953cdf0e10cSrcweir         catch (lang::DisposedException&)
954cdf0e10cSrcweir         {
955cdf0e10cSrcweir             Dispose();
956cdf0e10cSrcweir         }
957cdf0e10cSrcweir         catch (RuntimeException&)
958cdf0e10cSrcweir         {
959cdf0e10cSrcweir             DBG_UNHANDLED_EXCEPTION();
960cdf0e10cSrcweir         }
961cdf0e10cSrcweir     }
962cdf0e10cSrcweir }
963cdf0e10cSrcweir 
964cdf0e10cSrcweir 
965cdf0e10cSrcweir 
966cdf0e10cSrcweir 
ResourceIdToString(const Reference<XResourceId> & rxResourceId)967cdf0e10cSrcweir OUString FrameworkHelper::ResourceIdToString (const Reference<XResourceId>& rxResourceId)
968cdf0e10cSrcweir {
969cdf0e10cSrcweir     OUString sString;
970cdf0e10cSrcweir     if (rxResourceId.is())
971cdf0e10cSrcweir     {
972cdf0e10cSrcweir         sString += rxResourceId->getResourceURL();
973cdf0e10cSrcweir         if (rxResourceId->hasAnchor())
974cdf0e10cSrcweir         {
975cdf0e10cSrcweir             Sequence<OUString> aAnchorURLs (rxResourceId->getAnchorURLs());
976cdf0e10cSrcweir             for (sal_Int32 nIndex=0; nIndex<aAnchorURLs.getLength(); ++nIndex)
977cdf0e10cSrcweir             {
978cdf0e10cSrcweir                 sString += OUString::createFromAscii(" | ");
979cdf0e10cSrcweir                 sString += aAnchorURLs[nIndex];
980cdf0e10cSrcweir             }
981cdf0e10cSrcweir         }
982cdf0e10cSrcweir     }
983cdf0e10cSrcweir     return sString;
984cdf0e10cSrcweir }
985cdf0e10cSrcweir 
986cdf0e10cSrcweir 
987cdf0e10cSrcweir 
988cdf0e10cSrcweir 
CreateResourceId(const::rtl::OUString & rsResourceURL)989cdf0e10cSrcweir Reference<XResourceId> FrameworkHelper::CreateResourceId (const ::rtl::OUString& rsResourceURL)
990cdf0e10cSrcweir {
991cdf0e10cSrcweir     return new ::sd::framework::ResourceId(rsResourceURL);
992cdf0e10cSrcweir }
993cdf0e10cSrcweir 
994cdf0e10cSrcweir 
995cdf0e10cSrcweir 
996cdf0e10cSrcweir 
CreateResourceId(const OUString & rsResourceURL,const OUString & rsAnchorURL)997cdf0e10cSrcweir Reference<XResourceId> FrameworkHelper::CreateResourceId (
998cdf0e10cSrcweir     const OUString& rsResourceURL,
999cdf0e10cSrcweir     const OUString& rsAnchorURL)
1000cdf0e10cSrcweir {
1001cdf0e10cSrcweir     return new ::sd::framework::ResourceId(rsResourceURL, rsAnchorURL);
1002cdf0e10cSrcweir }
1003cdf0e10cSrcweir 
1004cdf0e10cSrcweir 
1005cdf0e10cSrcweir 
1006cdf0e10cSrcweir 
CreateResourceId(const OUString & rsResourceURL,const OUString & rsFirstAnchorURL,const OUString & rsSecondAnchorURL)1007cdf0e10cSrcweir Reference<XResourceId> FrameworkHelper::CreateResourceId (
1008cdf0e10cSrcweir     const OUString& rsResourceURL,
1009cdf0e10cSrcweir     const OUString& rsFirstAnchorURL,
1010cdf0e10cSrcweir     const OUString& rsSecondAnchorURL)
1011cdf0e10cSrcweir {
1012cdf0e10cSrcweir     ::std::vector<OUString> aAnchorURLs (2);
1013cdf0e10cSrcweir     aAnchorURLs[0] = rsFirstAnchorURL;
1014cdf0e10cSrcweir     aAnchorURLs[1] = rsSecondAnchorURL;
1015cdf0e10cSrcweir     return new ::sd::framework::ResourceId(rsResourceURL, aAnchorURLs);
1016cdf0e10cSrcweir }
1017cdf0e10cSrcweir 
1018cdf0e10cSrcweir 
1019cdf0e10cSrcweir 
1020cdf0e10cSrcweir 
CreateResourceId(const::rtl::OUString & rsResourceURL,const Reference<XResourceId> & rxAnchorId)1021cdf0e10cSrcweir Reference<XResourceId> FrameworkHelper::CreateResourceId (
1022cdf0e10cSrcweir     const ::rtl::OUString& rsResourceURL,
1023cdf0e10cSrcweir     const Reference<XResourceId>& rxAnchorId)
1024cdf0e10cSrcweir {
1025cdf0e10cSrcweir     if (rxAnchorId.is())
1026cdf0e10cSrcweir         return new ::sd::framework::ResourceId(
1027cdf0e10cSrcweir             rsResourceURL,
1028cdf0e10cSrcweir             rxAnchorId->getResourceURL(),
1029cdf0e10cSrcweir             rxAnchorId->getAnchorURLs());
1030cdf0e10cSrcweir     else
1031cdf0e10cSrcweir         return new ::sd::framework::ResourceId(rsResourceURL);
1032cdf0e10cSrcweir }
1033cdf0e10cSrcweir 
1034cdf0e10cSrcweir 
1035cdf0e10cSrcweir 
1036cdf0e10cSrcweir 
GetConfigurationController(void) const1037cdf0e10cSrcweir Reference<XConfigurationController> FrameworkHelper::GetConfigurationController (void) const
1038cdf0e10cSrcweir {
1039cdf0e10cSrcweir     return mxConfigurationController;
1040cdf0e10cSrcweir }
1041cdf0e10cSrcweir 
1042cdf0e10cSrcweir 
1043cdf0e10cSrcweir 
1044cdf0e10cSrcweir 
1045cdf0e10cSrcweir //----- FrameworkHelper::DisposeListener --------------------------------------
1046cdf0e10cSrcweir 
DisposeListener(const::boost::shared_ptr<FrameworkHelper> & rpHelper)1047cdf0e10cSrcweir FrameworkHelper::DisposeListener::DisposeListener (
1048cdf0e10cSrcweir     const ::boost::shared_ptr<FrameworkHelper>& rpHelper)
1049cdf0e10cSrcweir     : FrameworkHelperDisposeListenerInterfaceBase(maMutex),
1050cdf0e10cSrcweir       mpHelper(rpHelper)
1051cdf0e10cSrcweir {
1052cdf0e10cSrcweir     Reference<XComponent> xComponent (mpHelper->mxConfigurationController, UNO_QUERY);
1053cdf0e10cSrcweir     if (xComponent.is())
1054cdf0e10cSrcweir         xComponent->addEventListener(this);
1055cdf0e10cSrcweir }
1056cdf0e10cSrcweir 
1057cdf0e10cSrcweir 
1058cdf0e10cSrcweir 
1059cdf0e10cSrcweir 
~DisposeListener(void)1060cdf0e10cSrcweir FrameworkHelper::DisposeListener::~DisposeListener (void)
1061cdf0e10cSrcweir {
1062cdf0e10cSrcweir }
1063cdf0e10cSrcweir 
1064cdf0e10cSrcweir 
1065cdf0e10cSrcweir 
1066cdf0e10cSrcweir 
disposing(void)1067cdf0e10cSrcweir void SAL_CALL FrameworkHelper::DisposeListener::disposing (void)
1068cdf0e10cSrcweir {
1069cdf0e10cSrcweir     Reference<XComponent> xComponent (mpHelper->mxConfigurationController, UNO_QUERY);
1070cdf0e10cSrcweir     if (xComponent.is())
1071cdf0e10cSrcweir         xComponent->removeEventListener(this);
1072cdf0e10cSrcweir 
1073cdf0e10cSrcweir     mpHelper.reset();
1074cdf0e10cSrcweir }
1075cdf0e10cSrcweir 
1076cdf0e10cSrcweir 
1077cdf0e10cSrcweir 
1078cdf0e10cSrcweir 
disposing(const lang::EventObject & rEventObject)1079cdf0e10cSrcweir void SAL_CALL FrameworkHelper::DisposeListener::disposing (const lang::EventObject& rEventObject)
1080cdf0e10cSrcweir     throw(RuntimeException)
1081cdf0e10cSrcweir {
1082cdf0e10cSrcweir     if (mpHelper.get() != NULL)
1083cdf0e10cSrcweir         mpHelper->disposing(rEventObject);
1084cdf0e10cSrcweir }
1085cdf0e10cSrcweir 
1086cdf0e10cSrcweir 
1087cdf0e10cSrcweir 
1088cdf0e10cSrcweir 
1089cdf0e10cSrcweir //===== FrameworkHelperResourceIdFilter =======================================
1090cdf0e10cSrcweir 
FrameworkHelperResourceIdFilter(const Reference<XResourceId> & rxResourceId)1091cdf0e10cSrcweir FrameworkHelperResourceIdFilter::FrameworkHelperResourceIdFilter (
1092cdf0e10cSrcweir     const Reference<XResourceId>& rxResourceId)
1093cdf0e10cSrcweir     : mxResourceId(rxResourceId)
1094cdf0e10cSrcweir {
1095cdf0e10cSrcweir }
1096cdf0e10cSrcweir 
1097cdf0e10cSrcweir 
1098cdf0e10cSrcweir } } // end of namespace sd::framework
1099cdf0e10cSrcweir 
1100cdf0e10cSrcweir namespace {
1101cdf0e10cSrcweir 
1102cdf0e10cSrcweir //===== CallbackCaller ========================================================
1103cdf0e10cSrcweir 
CallbackCaller(::sd::ViewShellBase & rBase,const OUString & rsEventType,const::sd::framework::FrameworkHelper::ConfigurationChangeEventFilter & rFilter,const::sd::framework::FrameworkHelper::Callback & rCallback)1104cdf0e10cSrcweir CallbackCaller::CallbackCaller (
1105cdf0e10cSrcweir     ::sd::ViewShellBase& rBase,
1106cdf0e10cSrcweir     const OUString& rsEventType,
1107cdf0e10cSrcweir     const ::sd::framework::FrameworkHelper::ConfigurationChangeEventFilter& rFilter,
1108cdf0e10cSrcweir     const ::sd::framework::FrameworkHelper::Callback& rCallback)
1109cdf0e10cSrcweir     : CallbackCallerInterfaceBase(MutexOwner::maMutex),
1110cdf0e10cSrcweir       msEventType(rsEventType),
1111cdf0e10cSrcweir       mxConfigurationController(),
1112cdf0e10cSrcweir       maFilter(rFilter),
1113cdf0e10cSrcweir       maCallback(rCallback)
1114cdf0e10cSrcweir {
1115cdf0e10cSrcweir     try
1116cdf0e10cSrcweir     {
1117cdf0e10cSrcweir         Reference<XControllerManager> xControllerManager (rBase.GetController(), UNO_QUERY_THROW);
1118cdf0e10cSrcweir         mxConfigurationController = xControllerManager->getConfigurationController();
1119cdf0e10cSrcweir         if (mxConfigurationController.is())
1120cdf0e10cSrcweir         {
1121cdf0e10cSrcweir             if (mxConfigurationController->hasPendingRequests())
1122cdf0e10cSrcweir                 mxConfigurationController->addConfigurationChangeListener(this,msEventType,Any());
1123cdf0e10cSrcweir             else
1124cdf0e10cSrcweir             {
1125cdf0e10cSrcweir                 // There are no requests waiting to be processed.  Therefore
1126cdf0e10cSrcweir                 // no event, especially not the one we are waiting for, will
1127cdf0e10cSrcweir                 // be sent in the near future and the callback would never be
1128cdf0e10cSrcweir                 // called.
1129cdf0e10cSrcweir                 // Call the callback now and tell him that the event it is
1130cdf0e10cSrcweir                 // waiting for was not sent.
1131cdf0e10cSrcweir                 mxConfigurationController = NULL;
1132cdf0e10cSrcweir                 maCallback(false);
1133cdf0e10cSrcweir             }
1134cdf0e10cSrcweir         }
1135cdf0e10cSrcweir     }
1136cdf0e10cSrcweir     catch (RuntimeException&)
1137cdf0e10cSrcweir     {
1138cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
1139cdf0e10cSrcweir     }
1140cdf0e10cSrcweir }
1141cdf0e10cSrcweir 
1142cdf0e10cSrcweir 
1143cdf0e10cSrcweir 
1144cdf0e10cSrcweir 
~CallbackCaller(void)1145cdf0e10cSrcweir CallbackCaller::~CallbackCaller (void)
1146cdf0e10cSrcweir {
1147cdf0e10cSrcweir }
1148cdf0e10cSrcweir 
1149cdf0e10cSrcweir 
1150cdf0e10cSrcweir 
1151cdf0e10cSrcweir 
disposing(void)1152cdf0e10cSrcweir void CallbackCaller::disposing (void)
1153cdf0e10cSrcweir {
1154cdf0e10cSrcweir     try
1155cdf0e10cSrcweir     {
1156cdf0e10cSrcweir         if (mxConfigurationController.is())
1157cdf0e10cSrcweir         {
1158cdf0e10cSrcweir             Reference<XConfigurationController> xCC (mxConfigurationController);
1159cdf0e10cSrcweir             mxConfigurationController = NULL;
1160cdf0e10cSrcweir             xCC->removeConfigurationChangeListener(this);
1161cdf0e10cSrcweir         }
1162cdf0e10cSrcweir     }
1163cdf0e10cSrcweir     catch (RuntimeException&)
1164cdf0e10cSrcweir     {
1165cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
1166cdf0e10cSrcweir     }
1167cdf0e10cSrcweir }
1168cdf0e10cSrcweir 
1169cdf0e10cSrcweir 
1170cdf0e10cSrcweir 
1171cdf0e10cSrcweir 
disposing(const lang::EventObject & rEvent)1172cdf0e10cSrcweir void SAL_CALL CallbackCaller::disposing (const lang::EventObject& rEvent)
1173cdf0e10cSrcweir     throw (RuntimeException)
1174cdf0e10cSrcweir {
1175cdf0e10cSrcweir     if (rEvent.Source == mxConfigurationController)
1176cdf0e10cSrcweir     {
1177cdf0e10cSrcweir         mxConfigurationController = NULL;
1178cdf0e10cSrcweir         maCallback(false);
1179cdf0e10cSrcweir     }
1180cdf0e10cSrcweir }
1181cdf0e10cSrcweir 
1182cdf0e10cSrcweir 
1183cdf0e10cSrcweir 
1184cdf0e10cSrcweir 
notifyConfigurationChange(const ConfigurationChangeEvent & rEvent)1185cdf0e10cSrcweir void SAL_CALL CallbackCaller::notifyConfigurationChange (
1186cdf0e10cSrcweir     const ConfigurationChangeEvent& rEvent)
1187cdf0e10cSrcweir     throw (RuntimeException)
1188cdf0e10cSrcweir {
1189cdf0e10cSrcweir     if (rEvent.Type.equals(msEventType) && maFilter(rEvent))
1190cdf0e10cSrcweir     {
1191cdf0e10cSrcweir         maCallback(true);
1192cdf0e10cSrcweir         if (mxConfigurationController.is())
1193cdf0e10cSrcweir         {
1194cdf0e10cSrcweir             // Reset the reference to the configuration controller so that
1195cdf0e10cSrcweir             // dispose() will not try to remove the listener a second time.
1196cdf0e10cSrcweir             Reference<XConfigurationController> xCC (mxConfigurationController);
1197cdf0e10cSrcweir             mxConfigurationController = NULL;
1198cdf0e10cSrcweir 
1199cdf0e10cSrcweir             // Removing this object from the controller may very likely lead
1200cdf0e10cSrcweir             // to its destruction, so no calls after that.
1201cdf0e10cSrcweir             xCC->removeConfigurationChangeListener(this);
1202cdf0e10cSrcweir         }
1203cdf0e10cSrcweir     }
1204cdf0e10cSrcweir }
1205cdf0e10cSrcweir 
1206cdf0e10cSrcweir 
1207cdf0e10cSrcweir 
1208cdf0e10cSrcweir 
1209cdf0e10cSrcweir //----- LifetimeController -------------------------------------------------
1210cdf0e10cSrcweir 
LifetimeController(::sd::ViewShellBase & rBase)1211cdf0e10cSrcweir LifetimeController::LifetimeController (::sd::ViewShellBase& rBase)
1212cdf0e10cSrcweir     : LifetimeControllerInterfaceBase(maMutex),
1213cdf0e10cSrcweir       mrBase(rBase),
1214cdf0e10cSrcweir       mbListeningToViewShellBase(false),
1215cdf0e10cSrcweir       mbListeningToController(false)
1216cdf0e10cSrcweir {
1217cdf0e10cSrcweir     // Register as listener at the ViewShellBase.  Because that is not done
1218cdf0e10cSrcweir     // via a reference we have to increase the reference count manually.
1219cdf0e10cSrcweir     // This is necessary even though listening to the XController did
1220cdf0e10cSrcweir     // increase the reference count because the controller may release its
1221cdf0e10cSrcweir     // reference to us before the ViewShellBase is destroyed.
1222cdf0e10cSrcweir     StartListening(mrBase);
1223cdf0e10cSrcweir     acquire();
1224cdf0e10cSrcweir     mbListeningToViewShellBase = true;
1225cdf0e10cSrcweir 
1226cdf0e10cSrcweir     Reference<XComponent> xComponent (rBase.GetController(), UNO_QUERY);
1227cdf0e10cSrcweir     if (xComponent.is())
1228cdf0e10cSrcweir     {
1229cdf0e10cSrcweir         xComponent->addEventListener(this);
1230cdf0e10cSrcweir         mbListeningToController = true;
1231cdf0e10cSrcweir     }
1232cdf0e10cSrcweir }
1233cdf0e10cSrcweir 
1234cdf0e10cSrcweir 
1235cdf0e10cSrcweir 
1236cdf0e10cSrcweir 
~LifetimeController(void)1237cdf0e10cSrcweir LifetimeController::~LifetimeController (void)
1238cdf0e10cSrcweir {
1239cdf0e10cSrcweir     OSL_ASSERT(!mbListeningToController && !mbListeningToViewShellBase);
1240cdf0e10cSrcweir }
1241cdf0e10cSrcweir 
1242cdf0e10cSrcweir 
1243cdf0e10cSrcweir 
1244cdf0e10cSrcweir 
disposing(void)1245cdf0e10cSrcweir void LifetimeController::disposing (void)
1246cdf0e10cSrcweir {
1247cdf0e10cSrcweir }
1248cdf0e10cSrcweir 
1249cdf0e10cSrcweir 
1250cdf0e10cSrcweir 
1251cdf0e10cSrcweir 
disposing(const lang::EventObject & rEvent)1252cdf0e10cSrcweir void SAL_CALL LifetimeController::disposing (const lang::EventObject& rEvent)
1253cdf0e10cSrcweir     throw(RuntimeException)
1254cdf0e10cSrcweir {
1255cdf0e10cSrcweir     (void)rEvent;
1256cdf0e10cSrcweir     mbListeningToController = false;
1257cdf0e10cSrcweir     Update();
1258cdf0e10cSrcweir }
1259cdf0e10cSrcweir 
1260cdf0e10cSrcweir 
1261cdf0e10cSrcweir 
1262cdf0e10cSrcweir 
Notify(SfxBroadcaster & rBroadcaster,const SfxHint & rHint)1263cdf0e10cSrcweir void LifetimeController::Notify (SfxBroadcaster& rBroadcaster, const SfxHint& rHint)
1264cdf0e10cSrcweir {
1265cdf0e10cSrcweir     (void)rBroadcaster;
1266cdf0e10cSrcweir     const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
1267cdf0e10cSrcweir     if (pSimpleHint != NULL && pSimpleHint->GetId() == SFX_HINT_DYING)
1268cdf0e10cSrcweir     {
1269cdf0e10cSrcweir         mbListeningToViewShellBase = false;
1270cdf0e10cSrcweir         Update();
1271cdf0e10cSrcweir         release();
1272cdf0e10cSrcweir     }
1273cdf0e10cSrcweir }
1274cdf0e10cSrcweir 
1275cdf0e10cSrcweir 
1276cdf0e10cSrcweir 
1277cdf0e10cSrcweir 
Update(void)1278cdf0e10cSrcweir void LifetimeController::Update (void)
1279cdf0e10cSrcweir {
1280cdf0e10cSrcweir     if (mbListeningToViewShellBase && mbListeningToController)
1281cdf0e10cSrcweir     {
1282cdf0e10cSrcweir         // Both the controller and the ViewShellBase are alive.  Keep
1283cdf0e10cSrcweir         // waiting for their destruction.
1284cdf0e10cSrcweir     }
1285cdf0e10cSrcweir     else if (mbListeningToViewShellBase)
1286cdf0e10cSrcweir     {
1287cdf0e10cSrcweir         // The controller has been destroyed but the ViewShellBase is still
1288cdf0e10cSrcweir         // alive.  Dispose the associated FrameworkHelper but keep it around
1289cdf0e10cSrcweir         // so that no new instance is created for the dying framework.
1290cdf0e10cSrcweir         ::sd::framework::FrameworkHelper::DisposeInstance(mrBase);
1291cdf0e10cSrcweir     }
1292cdf0e10cSrcweir     else
1293cdf0e10cSrcweir     {
1294cdf0e10cSrcweir         // Both the controller and the ViewShellBase have been destroyed.
1295cdf0e10cSrcweir         // Remove the FrameworkHelper so that the next call its Instance()
1296cdf0e10cSrcweir         // method can create a new instance.
1297cdf0e10cSrcweir         ::sd::framework::FrameworkHelper::ReleaseInstance(mrBase);
1298cdf0e10cSrcweir     }
1299cdf0e10cSrcweir }
1300cdf0e10cSrcweir 
1301cdf0e10cSrcweir 
1302cdf0e10cSrcweir 
1303cdf0e10cSrcweir } // end of anonymous namespace.
1304