1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2008 by Sun Microsystems, Inc. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * $RCSfile: ToolPanelModule.cxx,v $ 10 * $Revision: 1.4 $ 11 * 12 * This file is part of OpenOffice.org. 13 * 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. 17 * 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). 23 * 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. 28 * 29 ************************************************************************/ 30 31 #include "precompiled_sd.hxx" 32 33 #include "ToolPanelModule.hxx" 34 #include "ReadOnlyModeObserver.hxx" 35 #include "framework/FrameworkHelper.hxx" 36 37 #include <com/sun/star/lang/XInitialization.hpp> 38 #include <com/sun/star/drawing/framework/XControllerManager.hpp> 39 40 #include <comphelper/processfactory.hxx> 41 #include <cppuhelper/compbase1.hxx> 42 #include <boost/enable_shared_from_this.hpp> 43 44 using namespace ::com::sun::star; 45 using namespace ::com::sun::star::uno; 46 using namespace ::com::sun::star::drawing::framework; 47 using ::rtl::OUString; 48 using ::sd::framework::FrameworkHelper; 49 50 51 namespace sd { namespace framework { 52 53 namespace { 54 55 typedef ::cppu::WeakComponentImplHelper1 < 56 ::com::sun::star::frame::XStatusListener 57 > LocalReadOnlyModeObserverInterfaceBase; 58 59 /** This local class enables or disables the ResourceManager of a 60 ToolPanelModule. It connects to a ReadOnlyModeObserver and is called 61 when the state of the .uno:EditDoc command changes. When either the 62 ResourceManager or the ReadOnlyModeObserver are disposed then the 63 LocalReadOnlyModeObserver disposes itself. The link 64 between the ResourceManager and the ReadOnlyModeObserver is removed and 65 the ReadOnlyModeObserver typically looses its last reference and is 66 destroyed. 67 */ 68 class LocalReadOnlyModeObserver 69 : private MutexOwner, 70 public LocalReadOnlyModeObserverInterfaceBase 71 { 72 public: 73 LocalReadOnlyModeObserver ( 74 const Reference<frame::XController>& rxController, 75 const ::rtl::Reference<ResourceManager>& rpResourceManager) 76 : MutexOwner(), 77 LocalReadOnlyModeObserverInterfaceBase(maMutex), 78 mpResourceManager(rpResourceManager), 79 mpObserver(new ReadOnlyModeObserver(rxController)) 80 { 81 mpObserver->AddStatusListener(this); 82 83 Reference<lang::XComponent> xComponent ( 84 static_cast<XWeak*>(mpResourceManager.get()), UNO_QUERY); 85 if (xComponent.is()) 86 xComponent->addEventListener(this); 87 } 88 89 ~LocalReadOnlyModeObserver (void) 90 { 91 } 92 93 virtual void SAL_CALL disposing (void) 94 { 95 Reference<lang::XComponent> xComponent (static_cast<XWeak*>(mpObserver.get()), UNO_QUERY); 96 if (xComponent.is()) 97 xComponent->dispose(); 98 99 xComponent = Reference<lang::XComponent>( 100 static_cast<XWeak*>(mpResourceManager.get()), UNO_QUERY); 101 if (xComponent.is()) 102 xComponent->removeEventListener(this); 103 104 } 105 106 virtual void SAL_CALL disposing (const com::sun::star::lang::EventObject& rEvent) 107 throw(RuntimeException) 108 { 109 if (rEvent.Source == Reference<XInterface>(static_cast<XWeak*>(mpObserver.get()))) 110 { 111 mpObserver = NULL; 112 } 113 else if (rEvent.Source == Reference<XInterface>( 114 static_cast<XWeak*>(mpResourceManager.get()))) 115 { 116 mpResourceManager = NULL; 117 } 118 dispose(); 119 } 120 121 virtual void SAL_CALL statusChanged (const com::sun::star::frame::FeatureStateEvent& rEvent) 122 throw(RuntimeException) 123 { 124 bool bReadWrite (true); 125 if (rEvent.IsEnabled) 126 rEvent.State >>= bReadWrite; 127 128 if (bReadWrite) 129 mpResourceManager->Enable(); 130 else 131 mpResourceManager->Disable(); 132 } 133 134 private: 135 ::rtl::Reference<ResourceManager> mpResourceManager; 136 ::rtl::Reference<ReadOnlyModeObserver> mpObserver; 137 138 }; 139 } 140 141 142 143 144 //===== ToolPanelModule ==================================================== 145 146 void ToolPanelModule::Initialize (const Reference<frame::XController>& rxController) 147 { 148 ::rtl::Reference<ResourceManager> pResourceManager ( 149 new ResourceManager( 150 rxController, 151 FrameworkHelper::CreateResourceId( 152 FrameworkHelper::msTaskPaneURL, 153 FrameworkHelper::msRightPaneURL))); 154 pResourceManager->AddActiveMainView(FrameworkHelper::msImpressViewURL); 155 pResourceManager->AddActiveMainView(FrameworkHelper::msNotesViewURL); 156 pResourceManager->AddActiveMainView(FrameworkHelper::msHandoutViewURL); 157 pResourceManager->AddActiveMainView(FrameworkHelper::msSlideSorterURL); 158 159 new LocalReadOnlyModeObserver(rxController, pResourceManager); 160 } 161 162 163 164 165 } } // end of namespace sd::framework 166