1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: TaskPaneModule.cxx,v $
12 * This file is part of OpenOffice.org.
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.
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).
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.
29 ************************************************************************/
31 #include "precompiled_sd.hxx"
33 #include "TaskPaneModule.hxx"
34 #include "ReadOnlyModeObserver.hxx"
35 #include "framework/FrameworkHelper.hxx"
37 #include <com/sun/star/lang/XInitialization.hpp>
38 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
40 #include <comphelper/processfactory.hxx>
41 #include <cppuhelper/compbase1.hxx>
42 #include <boost/enable_shared_from_this.hpp>
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
;
51 namespace sd
{ namespace framework
{
55 typedef ::cppu::WeakComponentImplHelper1
<
56 ::com::sun::star::frame::XStatusListener
57 > LocalReadOnlyModeObserverInterfaceBase
;
59 /** This local class enables or disables the ResourceManager of a
60 TaskPaneModule. 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
68 class LocalReadOnlyModeObserver
70 public LocalReadOnlyModeObserverInterfaceBase
73 LocalReadOnlyModeObserver (
74 const Reference
<frame::XController
>& rxController
,
75 const ::rtl::Reference
<ResourceManager
>& rpResourceManager
)
77 LocalReadOnlyModeObserverInterfaceBase(maMutex
),
78 mpResourceManager(rpResourceManager
),
79 mpObserver(new ReadOnlyModeObserver(rxController
))
81 mpObserver
->AddStatusListener(this);
83 Reference
<lang::XComponent
> xComponent (
84 static_cast<XWeak
*>(mpResourceManager
.get()), UNO_QUERY
);
86 xComponent
->addEventListener(this);
89 ~LocalReadOnlyModeObserver (void)
93 virtual void SAL_CALL
disposing (void)
95 Reference
<lang::XComponent
> xComponent (static_cast<XWeak
*>(mpObserver
.get()), UNO_QUERY
);
97 xComponent
->dispose();
99 xComponent
= Reference
<lang::XComponent
>(
100 static_cast<XWeak
*>(mpResourceManager
.get()), UNO_QUERY
);
102 xComponent
->removeEventListener(this);
106 virtual void SAL_CALL
disposing (const com::sun::star::lang::EventObject
& rEvent
)
107 throw(RuntimeException
)
109 if (rEvent
.Source
== Reference
<XInterface
>(static_cast<XWeak
*>(mpObserver
.get())))
113 else if (rEvent
.Source
== Reference
<XInterface
>(
114 static_cast<XWeak
*>(mpResourceManager
.get())))
116 mpResourceManager
= NULL
;
121 virtual void SAL_CALL
statusChanged (const com::sun::star::frame::FeatureStateEvent
& rEvent
)
122 throw(RuntimeException
)
124 bool bReadWrite (true);
125 if (rEvent
.IsEnabled
)
126 rEvent
.State
>>= bReadWrite
;
129 mpResourceManager
->Enable();
131 mpResourceManager
->Disable();
135 ::rtl::Reference
<ResourceManager
> mpResourceManager
;
136 ::rtl::Reference
<ReadOnlyModeObserver
> mpObserver
;
144 //===== TaskPaneModule ====================================================
146 void TaskPaneModule::Initialize (const Reference
<frame::XController
>& rxController
)
148 ::rtl::Reference
<ResourceManager
> pResourceManager (
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
);
159 new LocalReadOnlyModeObserver(rxController
, pResourceManager
);
165 } } // end of namespace sd::framework