1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2008 by Sun Microsystems, Inc.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * $RCSfile: ToolPanelModule.cxx,v $
10*cdf0e10cSrcweir  * $Revision: 1.4 $
11*cdf0e10cSrcweir  *
12*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
13*cdf0e10cSrcweir  *
14*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
15*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
16*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
17*cdf0e10cSrcweir  *
18*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
19*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
22*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
23*cdf0e10cSrcweir  *
24*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
25*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
26*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
27*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
28*cdf0e10cSrcweir  *
29*cdf0e10cSrcweir  ************************************************************************/
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "precompiled_sd.hxx"
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include "ToolPanelModule.hxx"
34*cdf0e10cSrcweir #include "ReadOnlyModeObserver.hxx"
35*cdf0e10cSrcweir #include "framework/FrameworkHelper.hxx"
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/drawing/framework/XControllerManager.hpp>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
41*cdf0e10cSrcweir #include <cppuhelper/compbase1.hxx>
42*cdf0e10cSrcweir #include <boost/enable_shared_from_this.hpp>
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir using namespace ::com::sun::star;
45*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
46*cdf0e10cSrcweir using namespace ::com::sun::star::drawing::framework;
47*cdf0e10cSrcweir using ::rtl::OUString;
48*cdf0e10cSrcweir using ::sd::framework::FrameworkHelper;
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir namespace sd { namespace framework {
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir namespace {
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir typedef ::cppu::WeakComponentImplHelper1 <
56*cdf0e10cSrcweir       ::com::sun::star::frame::XStatusListener
57*cdf0e10cSrcweir     > LocalReadOnlyModeObserverInterfaceBase;
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir /** This local class enables or disables the ResourceManager of a
60*cdf0e10cSrcweir     ToolPanelModule.  It connects to a ReadOnlyModeObserver and is called
61*cdf0e10cSrcweir     when the state of the .uno:EditDoc command changes.  When either the
62*cdf0e10cSrcweir     ResourceManager or the ReadOnlyModeObserver are disposed then the
63*cdf0e10cSrcweir     LocalReadOnlyModeObserver disposes itself.  The link
64*cdf0e10cSrcweir     between the ResourceManager and the ReadOnlyModeObserver is removed and
65*cdf0e10cSrcweir     the ReadOnlyModeObserver typically looses its last reference and is
66*cdf0e10cSrcweir     destroyed.
67*cdf0e10cSrcweir */
68*cdf0e10cSrcweir class LocalReadOnlyModeObserver
69*cdf0e10cSrcweir     : private MutexOwner,
70*cdf0e10cSrcweir       public LocalReadOnlyModeObserverInterfaceBase
71*cdf0e10cSrcweir {
72*cdf0e10cSrcweir public:
73*cdf0e10cSrcweir     LocalReadOnlyModeObserver (
74*cdf0e10cSrcweir         const Reference<frame::XController>& rxController,
75*cdf0e10cSrcweir         const ::rtl::Reference<ResourceManager>& rpResourceManager)
76*cdf0e10cSrcweir         : MutexOwner(),
77*cdf0e10cSrcweir           LocalReadOnlyModeObserverInterfaceBase(maMutex),
78*cdf0e10cSrcweir           mpResourceManager(rpResourceManager),
79*cdf0e10cSrcweir           mpObserver(new ReadOnlyModeObserver(rxController))
80*cdf0e10cSrcweir     {
81*cdf0e10cSrcweir         mpObserver->AddStatusListener(this);
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir         Reference<lang::XComponent> xComponent (
84*cdf0e10cSrcweir             static_cast<XWeak*>(mpResourceManager.get()), UNO_QUERY);
85*cdf0e10cSrcweir         if (xComponent.is())
86*cdf0e10cSrcweir             xComponent->addEventListener(this);
87*cdf0e10cSrcweir     }
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir     ~LocalReadOnlyModeObserver (void)
90*cdf0e10cSrcweir     {
91*cdf0e10cSrcweir     }
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir     virtual void SAL_CALL disposing (void)
94*cdf0e10cSrcweir     {
95*cdf0e10cSrcweir         Reference<lang::XComponent> xComponent (static_cast<XWeak*>(mpObserver.get()), UNO_QUERY);
96*cdf0e10cSrcweir         if (xComponent.is())
97*cdf0e10cSrcweir             xComponent->dispose();
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir         xComponent = Reference<lang::XComponent>(
100*cdf0e10cSrcweir             static_cast<XWeak*>(mpResourceManager.get()), UNO_QUERY);
101*cdf0e10cSrcweir         if (xComponent.is())
102*cdf0e10cSrcweir             xComponent->removeEventListener(this);
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir     }
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir     virtual void SAL_CALL disposing (const com::sun::star::lang::EventObject& rEvent)
107*cdf0e10cSrcweir         throw(RuntimeException)
108*cdf0e10cSrcweir     {
109*cdf0e10cSrcweir         if (rEvent.Source == Reference<XInterface>(static_cast<XWeak*>(mpObserver.get())))
110*cdf0e10cSrcweir         {
111*cdf0e10cSrcweir             mpObserver = NULL;
112*cdf0e10cSrcweir         }
113*cdf0e10cSrcweir         else if (rEvent.Source == Reference<XInterface>(
114*cdf0e10cSrcweir             static_cast<XWeak*>(mpResourceManager.get())))
115*cdf0e10cSrcweir         {
116*cdf0e10cSrcweir             mpResourceManager = NULL;
117*cdf0e10cSrcweir         }
118*cdf0e10cSrcweir         dispose();
119*cdf0e10cSrcweir     }
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir     virtual void SAL_CALL statusChanged (const com::sun::star::frame::FeatureStateEvent& rEvent)
122*cdf0e10cSrcweir         throw(RuntimeException)
123*cdf0e10cSrcweir     {
124*cdf0e10cSrcweir         bool bReadWrite (true);
125*cdf0e10cSrcweir         if (rEvent.IsEnabled)
126*cdf0e10cSrcweir             rEvent.State >>= bReadWrite;
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir         if (bReadWrite)
129*cdf0e10cSrcweir             mpResourceManager->Enable();
130*cdf0e10cSrcweir         else
131*cdf0e10cSrcweir             mpResourceManager->Disable();
132*cdf0e10cSrcweir     }
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir private:
135*cdf0e10cSrcweir     ::rtl::Reference<ResourceManager> mpResourceManager;
136*cdf0e10cSrcweir     ::rtl::Reference<ReadOnlyModeObserver> mpObserver;
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir };
139*cdf0e10cSrcweir }
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir //===== ToolPanelModule ====================================================
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir void ToolPanelModule::Initialize (const Reference<frame::XController>& rxController)
147*cdf0e10cSrcweir {
148*cdf0e10cSrcweir     ::rtl::Reference<ResourceManager> pResourceManager (
149*cdf0e10cSrcweir         new ResourceManager(
150*cdf0e10cSrcweir             rxController,
151*cdf0e10cSrcweir             FrameworkHelper::CreateResourceId(
152*cdf0e10cSrcweir                 FrameworkHelper::msTaskPaneURL,
153*cdf0e10cSrcweir                 FrameworkHelper::msRightPaneURL)));
154*cdf0e10cSrcweir     pResourceManager->AddActiveMainView(FrameworkHelper::msImpressViewURL);
155*cdf0e10cSrcweir     pResourceManager->AddActiveMainView(FrameworkHelper::msNotesViewURL);
156*cdf0e10cSrcweir     pResourceManager->AddActiveMainView(FrameworkHelper::msHandoutViewURL);
157*cdf0e10cSrcweir     pResourceManager->AddActiveMainView(FrameworkHelper::msSlideSorterURL);
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir     new LocalReadOnlyModeObserver(rxController, pResourceManager);
160*cdf0e10cSrcweir }
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir } } // end of namespace sd::framework
166