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