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