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: TaskPanelFactory.cxx,v $
11 * $Revision: 1.3.108.1 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #include "precompiled_sd.hxx"
33 #include "TaskPanelFactory.hxx"
34 #include "TaskPaneViewShell.hxx"
35 #include "DrawController.hxx"
36 #include "framework/FrameworkHelper.hxx"
37 #include <cppuhelper/compbase1.hxx>
39 using namespace ::com::sun::star
;
40 using namespace ::com::sun::star::uno
;
41 using namespace ::com::sun::star::drawing::framework
;
43 using ::rtl::OUString
;
44 using ::sd::framework::FrameworkHelper
;
45 using ::sd::toolpanel::TaskPaneViewShell
;
47 namespace sd
{ namespace framework
{
49 Reference
<XInterface
> SAL_CALL
TaskPanelFactory_createInstance (
50 const Reference
<XComponentContext
>& rxContext
)
52 return Reference
<XInterface
>(static_cast<XWeak
*>(new TaskPanelFactory(rxContext
)));
58 ::rtl::OUString
TaskPanelFactory_getImplementationName (void) throw(RuntimeException
)
60 return ::rtl::OUString(
61 RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Draw.framework.TaskPanelFactory"));
67 Sequence
<rtl::OUString
> SAL_CALL
TaskPanelFactory_getSupportedServiceNames (void)
68 throw (RuntimeException
)
70 static const OUString
sServiceName(
71 OUString::createFromAscii("com.sun.star.drawing.framework.TaskPanelFactory"));
72 return Sequence
<rtl::OUString
>(&sServiceName
, 1);
78 //===== ToolPanelResource =====================================================
82 typedef ::cppu::WeakComponentImplHelper1
<
83 css::drawing::framework::XResource
84 > TaskPanelResourceInterfaceBase
;
86 class TaskPanelResource
87 : private ::cppu::BaseMutex
,
88 public TaskPanelResourceInterfaceBase
92 const Reference
<XResourceId
>& rxResourceId
,
93 const TaskPaneViewShell::PanelId ePaneId
);
94 virtual ~TaskPanelResource ();
96 virtual void SAL_CALL
disposing ();
98 TaskPaneViewShell::PanelId
GetPaneId () const;
102 virtual Reference
<XResourceId
> SAL_CALL
getResourceId (void)
103 throw (css::uno::RuntimeException
);
105 virtual sal_Bool SAL_CALL
isAnchorOnly () throw (RuntimeException
)
109 const Reference
<XResourceId
> mxResourceId
;
110 const TaskPaneViewShell::PanelId mePaneId
;
113 } // end of anonymous namespace.
118 //===== TaskPanelFactory =======================================================
120 TaskPanelFactory::TaskPanelFactory (
121 const ::com::sun::star::uno::Reference
<com::sun::star::uno::XComponentContext
>& rxContext
)
122 : TaskPanelFactoryInterfaceBase(m_aMutex
),
123 mpViewShellBase(NULL
)
131 TaskPanelFactory::~TaskPanelFactory (void)
138 void SAL_CALL
TaskPanelFactory::disposing (void)
145 //===== XInitialization =======================================================
147 void SAL_CALL
TaskPanelFactory::initialize(
148 const ::com::sun::star::uno::Sequence
<com::sun::star::uno::Any
>& aArguments
)
149 throw (::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
)
151 if (aArguments
.getLength() > 0)
155 // Get the XController from the first argument.
156 Reference
<frame::XController
> xController (aArguments
[0], UNO_QUERY_THROW
);
158 // Tunnel through the controller to obtain access to the ViewShellBase.
161 Reference
<lang::XUnoTunnel
> xTunnel (xController
, UNO_QUERY_THROW
);
162 DrawController
* pController
163 = reinterpret_cast<DrawController
*>(
164 sal::static_int_cast
<sal_uIntPtr
>(
165 xTunnel
->getSomething(DrawController::getUnoTunnelId())));
166 if (pController
!= NULL
)
167 mpViewShellBase
= pController
->GetViewShellBase();
170 catch(RuntimeException
&)
174 Reference
<XControllerManager
> xCM (xController
, UNO_QUERY_THROW
);
175 Reference
<XConfigurationController
> xCC (
176 xCM
->getConfigurationController(), UNO_QUERY_THROW
);
177 xCC
->addResourceFactory(FrameworkHelper::msMasterPagesTaskPanelURL
, this);
178 xCC
->addResourceFactory(FrameworkHelper::msLayoutTaskPanelURL
, this);
179 xCC
->addResourceFactory(FrameworkHelper::msTableDesignPanelURL
, this);
180 xCC
->addResourceFactory(FrameworkHelper::msCustomAnimationTaskPanelURL
, this);
181 xCC
->addResourceFactory(FrameworkHelper::msSlideTransitionTaskPanelURL
, this);
183 catch (RuntimeException
&)
190 //===== XResourceController ===================================================
192 Reference
<XResource
> SAL_CALL
TaskPanelFactory::createResource (
193 const Reference
<XResourceId
>& rxResourceId
)
194 throw (RuntimeException
)
196 Reference
<XResource
> xResource
;
198 if ( ! rxResourceId
.is())
201 OUString
sResourceURL (rxResourceId
->getResourceURL());
203 if (sResourceURL
.match(FrameworkHelper::msTaskPanelURLPrefix
))
205 TaskPaneViewShell::PanelId
ePaneId (TaskPaneViewShell::PID_UNKNOWN
);
207 if (sResourceURL
.equals(FrameworkHelper::msMasterPagesTaskPanelURL
))
209 ePaneId
= TaskPaneViewShell::PID_MASTER_PAGES
;
211 else if (sResourceURL
.equals(FrameworkHelper::msLayoutTaskPanelURL
))
213 ePaneId
= TaskPaneViewShell::PID_LAYOUT
;
215 else if (sResourceURL
.equals(FrameworkHelper::msTableDesignPanelURL
))
217 ePaneId
= TaskPaneViewShell::PID_TABLE_DESIGN
;
219 else if (sResourceURL
.equals(FrameworkHelper::msCustomAnimationTaskPanelURL
))
221 ePaneId
= TaskPaneViewShell::PID_CUSTOM_ANIMATION
;
223 else if (sResourceURL
.equals(FrameworkHelper::msSlideTransitionTaskPanelURL
))
225 ePaneId
= TaskPaneViewShell::PID_SLIDE_TRANSITION
;
228 if (ePaneId
!=TaskPaneViewShell::PID_UNKNOWN
&& mpViewShellBase
!=NULL
)
230 toolpanel::TaskPaneViewShell
* pTaskPane
231 = dynamic_cast<toolpanel::TaskPaneViewShell
*>(
232 FrameworkHelper::Instance(*mpViewShellBase
)
233 ->GetViewShell(FrameworkHelper::msRightPaneURL
).get());
234 if (pTaskPane
!= NULL
)
236 xResource
= new TaskPanelResource(
239 pTaskPane
->ShowPanel(ePaneId
);
240 pTaskPane
->ExpandPanel(ePaneId
);
251 void SAL_CALL
TaskPanelFactory::releaseResource (
252 const Reference
<XResource
>& rxResource
)
253 throw (RuntimeException
)
255 toolpanel::TaskPaneViewShell
* pTaskPane
256 = dynamic_cast<toolpanel::TaskPaneViewShell
*>(
257 FrameworkHelper::Instance(*mpViewShellBase
)
258 ->GetViewShell(FrameworkHelper::msRightPaneURL
).get());
260 rtl::Reference
<TaskPanelResource
> pResource
= dynamic_cast<TaskPanelResource
*>(
263 if (pTaskPane
!= NULL
&& pResource
.is())
264 pTaskPane
->CollapsePanel(pResource
->GetPaneId());
266 Reference
<XComponent
> xComponent (rxResource
, UNO_QUERY
);
268 xComponent
->dispose();
274 //=============================================================================
276 void TaskPanelFactory::ThrowIfDisposed (void) const
277 throw (lang::DisposedException
)
279 if (rBHelper
.bDisposed
|| rBHelper
.bInDispose
)
281 throw lang::DisposedException (
282 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
283 "TaskPanelFactory object has already been disposed")),
284 const_cast<uno::XWeak
*>(static_cast<const uno::XWeak
*>(this)));
291 //===== ToolPanelResource =====================================================
295 TaskPanelResource::TaskPanelResource (
296 const Reference
<XResourceId
>& rxResourceId
,
297 const TaskPaneViewShell::PanelId ePaneId
)
298 : TaskPanelResourceInterfaceBase(m_aMutex
),
299 mxResourceId(rxResourceId
),
307 TaskPanelResource::~TaskPanelResource (void)
314 void SAL_CALL
TaskPanelResource::disposing ()
321 TaskPaneViewShell::PanelId
TaskPanelResource::GetPaneId () const
329 Reference
<XResourceId
> SAL_CALL
TaskPanelResource::getResourceId ()
330 throw (css::uno::RuntimeException
)
335 } // end of anonymous namespace
337 } } // end of namespace sd::framework