1*5b190011SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*5b190011SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*5b190011SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*5b190011SAndrew Rist * distributed with this work for additional information 6*5b190011SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*5b190011SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*5b190011SAndrew Rist * "License"); you may not use this file except in compliance 9*5b190011SAndrew Rist * with the License. You may obtain a copy of the License at 10*5b190011SAndrew Rist * 11*5b190011SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*5b190011SAndrew Rist * 13*5b190011SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*5b190011SAndrew Rist * software distributed under the License is distributed on an 15*5b190011SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*5b190011SAndrew Rist * KIND, either express or implied. See the License for the 17*5b190011SAndrew Rist * specific language governing permissions and limitations 18*5b190011SAndrew Rist * under the License. 19*5b190011SAndrew Rist * 20*5b190011SAndrew Rist *************************************************************/ 21*5b190011SAndrew Rist 22*5b190011SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include "precompiled_sd.hxx" 25cdf0e10cSrcweir 26cdf0e10cSrcweir #include "ToolPanelModule.hxx" 27cdf0e10cSrcweir #include "ReadOnlyModeObserver.hxx" 28cdf0e10cSrcweir #include "framework/FrameworkHelper.hxx" 29cdf0e10cSrcweir 30cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp> 31cdf0e10cSrcweir #include <com/sun/star/drawing/framework/XControllerManager.hpp> 32cdf0e10cSrcweir 33cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 34cdf0e10cSrcweir #include <cppuhelper/compbase1.hxx> 35cdf0e10cSrcweir #include <boost/enable_shared_from_this.hpp> 36cdf0e10cSrcweir 37cdf0e10cSrcweir using namespace ::com::sun::star; 38cdf0e10cSrcweir using namespace ::com::sun::star::uno; 39cdf0e10cSrcweir using namespace ::com::sun::star::drawing::framework; 40cdf0e10cSrcweir using ::rtl::OUString; 41cdf0e10cSrcweir using ::sd::framework::FrameworkHelper; 42cdf0e10cSrcweir 43cdf0e10cSrcweir 44cdf0e10cSrcweir namespace sd { namespace framework { 45cdf0e10cSrcweir 46cdf0e10cSrcweir namespace { 47cdf0e10cSrcweir 48cdf0e10cSrcweir typedef ::cppu::WeakComponentImplHelper1 < 49cdf0e10cSrcweir ::com::sun::star::frame::XStatusListener 50cdf0e10cSrcweir > LocalReadOnlyModeObserverInterfaceBase; 51cdf0e10cSrcweir 52cdf0e10cSrcweir /** This local class enables or disables the ResourceManager of a 53cdf0e10cSrcweir ToolPanelModule. It connects to a ReadOnlyModeObserver and is called 54cdf0e10cSrcweir when the state of the .uno:EditDoc command changes. When either the 55cdf0e10cSrcweir ResourceManager or the ReadOnlyModeObserver are disposed then the 56cdf0e10cSrcweir LocalReadOnlyModeObserver disposes itself. The link 57cdf0e10cSrcweir between the ResourceManager and the ReadOnlyModeObserver is removed and 58cdf0e10cSrcweir the ReadOnlyModeObserver typically looses its last reference and is 59cdf0e10cSrcweir destroyed. 60cdf0e10cSrcweir */ 61cdf0e10cSrcweir class LocalReadOnlyModeObserver 62cdf0e10cSrcweir : private MutexOwner, 63cdf0e10cSrcweir public LocalReadOnlyModeObserverInterfaceBase 64cdf0e10cSrcweir { 65cdf0e10cSrcweir public: 66cdf0e10cSrcweir LocalReadOnlyModeObserver ( 67cdf0e10cSrcweir const Reference<frame::XController>& rxController, 68cdf0e10cSrcweir const ::rtl::Reference<ResourceManager>& rpResourceManager) 69cdf0e10cSrcweir : MutexOwner(), 70cdf0e10cSrcweir LocalReadOnlyModeObserverInterfaceBase(maMutex), 71cdf0e10cSrcweir mpResourceManager(rpResourceManager), 72cdf0e10cSrcweir mpObserver(new ReadOnlyModeObserver(rxController)) 73cdf0e10cSrcweir { 74cdf0e10cSrcweir mpObserver->AddStatusListener(this); 75cdf0e10cSrcweir 76cdf0e10cSrcweir Reference<lang::XComponent> xComponent ( 77cdf0e10cSrcweir static_cast<XWeak*>(mpResourceManager.get()), UNO_QUERY); 78cdf0e10cSrcweir if (xComponent.is()) 79cdf0e10cSrcweir xComponent->addEventListener(this); 80cdf0e10cSrcweir } 81cdf0e10cSrcweir 82cdf0e10cSrcweir ~LocalReadOnlyModeObserver (void) 83cdf0e10cSrcweir { 84cdf0e10cSrcweir } 85cdf0e10cSrcweir 86cdf0e10cSrcweir virtual void SAL_CALL disposing (void) 87cdf0e10cSrcweir { 88cdf0e10cSrcweir Reference<lang::XComponent> xComponent (static_cast<XWeak*>(mpObserver.get()), UNO_QUERY); 89cdf0e10cSrcweir if (xComponent.is()) 90cdf0e10cSrcweir xComponent->dispose(); 91cdf0e10cSrcweir 92cdf0e10cSrcweir xComponent = Reference<lang::XComponent>( 93cdf0e10cSrcweir static_cast<XWeak*>(mpResourceManager.get()), UNO_QUERY); 94cdf0e10cSrcweir if (xComponent.is()) 95cdf0e10cSrcweir xComponent->removeEventListener(this); 96cdf0e10cSrcweir 97cdf0e10cSrcweir } 98cdf0e10cSrcweir 99cdf0e10cSrcweir virtual void SAL_CALL disposing (const com::sun::star::lang::EventObject& rEvent) 100cdf0e10cSrcweir throw(RuntimeException) 101cdf0e10cSrcweir { 102cdf0e10cSrcweir if (rEvent.Source == Reference<XInterface>(static_cast<XWeak*>(mpObserver.get()))) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir mpObserver = NULL; 105cdf0e10cSrcweir } 106cdf0e10cSrcweir else if (rEvent.Source == Reference<XInterface>( 107cdf0e10cSrcweir static_cast<XWeak*>(mpResourceManager.get()))) 108cdf0e10cSrcweir { 109cdf0e10cSrcweir mpResourceManager = NULL; 110cdf0e10cSrcweir } 111cdf0e10cSrcweir dispose(); 112cdf0e10cSrcweir } 113cdf0e10cSrcweir 114cdf0e10cSrcweir virtual void SAL_CALL statusChanged (const com::sun::star::frame::FeatureStateEvent& rEvent) 115cdf0e10cSrcweir throw(RuntimeException) 116cdf0e10cSrcweir { 117cdf0e10cSrcweir bool bReadWrite (true); 118cdf0e10cSrcweir if (rEvent.IsEnabled) 119cdf0e10cSrcweir rEvent.State >>= bReadWrite; 120cdf0e10cSrcweir 121cdf0e10cSrcweir if (bReadWrite) 122cdf0e10cSrcweir mpResourceManager->Enable(); 123cdf0e10cSrcweir else 124cdf0e10cSrcweir mpResourceManager->Disable(); 125cdf0e10cSrcweir } 126cdf0e10cSrcweir 127cdf0e10cSrcweir private: 128cdf0e10cSrcweir ::rtl::Reference<ResourceManager> mpResourceManager; 129cdf0e10cSrcweir ::rtl::Reference<ReadOnlyModeObserver> mpObserver; 130cdf0e10cSrcweir 131cdf0e10cSrcweir }; 132cdf0e10cSrcweir } 133cdf0e10cSrcweir 134cdf0e10cSrcweir 135cdf0e10cSrcweir 136cdf0e10cSrcweir 137cdf0e10cSrcweir //===== ToolPanelModule ==================================================== 138cdf0e10cSrcweir 139cdf0e10cSrcweir void ToolPanelModule::Initialize (const Reference<frame::XController>& rxController) 140cdf0e10cSrcweir { 141cdf0e10cSrcweir ::rtl::Reference<ResourceManager> pResourceManager ( 142cdf0e10cSrcweir new ResourceManager( 143cdf0e10cSrcweir rxController, 144cdf0e10cSrcweir FrameworkHelper::CreateResourceId( 145cdf0e10cSrcweir FrameworkHelper::msTaskPaneURL, 146cdf0e10cSrcweir FrameworkHelper::msRightPaneURL))); 147cdf0e10cSrcweir pResourceManager->AddActiveMainView(FrameworkHelper::msImpressViewURL); 148cdf0e10cSrcweir pResourceManager->AddActiveMainView(FrameworkHelper::msNotesViewURL); 149cdf0e10cSrcweir pResourceManager->AddActiveMainView(FrameworkHelper::msHandoutViewURL); 150cdf0e10cSrcweir pResourceManager->AddActiveMainView(FrameworkHelper::msSlideSorterURL); 151cdf0e10cSrcweir 152cdf0e10cSrcweir new LocalReadOnlyModeObserver(rxController, pResourceManager); 153cdf0e10cSrcweir } 154cdf0e10cSrcweir 155cdf0e10cSrcweir 156cdf0e10cSrcweir 157cdf0e10cSrcweir 158cdf0e10cSrcweir } } // end of namespace sd::framework 159