Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "TaskPanelFactory.hxx"
30 : : #include "taskpane/ToolPanelViewShell.hxx"
31 : : #include "DrawController.hxx"
32 : : #include "framework/FrameworkHelper.hxx"
33 : : #include <cppuhelper/compbase1.hxx>
34 : : #include <tools/diagnose_ex.h>
35 : :
36 : : using namespace ::com::sun::star;
37 : : using namespace ::com::sun::star::uno;
38 : : using namespace ::com::sun::star::lang;
39 : : using namespace ::com::sun::star::drawing::framework;
40 : :
41 : : using ::rtl::OUString;
42 : : using ::sd::framework::FrameworkHelper;
43 : :
44 : : namespace sd { namespace framework {
45 : :
46 : 16 : Reference<XInterface> SAL_CALL TaskPanelFactory_createInstance (
47 : : const Reference<XComponentContext>& rxContext)
48 : : {
49 [ + - ]: 16 : return Reference<XInterface>(static_cast<XWeak*>(new TaskPanelFactory(rxContext)));
50 : : }
51 : :
52 : :
53 : :
54 : :
55 : 28 : ::rtl::OUString TaskPanelFactory_getImplementationName (void) throw(RuntimeException)
56 : : {
57 : 28 : return ::rtl::OUString("com.sun.star.comp.Draw.framework.TaskPanelFactory");
58 : : }
59 : :
60 : :
61 : :
62 : :
63 : 6 : Sequence<rtl::OUString> SAL_CALL TaskPanelFactory_getSupportedServiceNames (void)
64 : : throw (RuntimeException)
65 : : {
66 : 6 : const OUString sServiceName("com.sun.star.drawing.framework.TaskPanelFactory");
67 [ + - ]: 6 : return Sequence<rtl::OUString>(&sServiceName, 1);
68 : : }
69 : :
70 : :
71 : :
72 : :
73 : : //===== ToolPanelResource =====================================================
74 : :
75 : : namespace {
76 : :
77 : : typedef ::cppu::WeakComponentImplHelper1 <
78 : : css::drawing::framework::XResource
79 : : > TaskPanelResourceInterfaceBase;
80 : :
81 : : class TaskPanelResource
82 : : : private ::cppu::BaseMutex,
83 : : public TaskPanelResourceInterfaceBase
84 : : {
85 : : public:
86 : : TaskPanelResource (
87 : : const Reference<XResourceId>& rxResourceId );
88 : : virtual ~TaskPanelResource ();
89 : :
90 : : virtual void SAL_CALL disposing ();
91 : :
92 : : // XResource
93 : :
94 : : virtual Reference<XResourceId> SAL_CALL getResourceId (void)
95 : : throw (css::uno::RuntimeException);
96 : :
97 : 38 : virtual sal_Bool SAL_CALL isAnchorOnly () throw (RuntimeException)
98 : 38 : { return false; }
99 : :
100 : : private:
101 : : const Reference<XResourceId> mxResourceId;
102 : : };
103 : :
104 : : } // end of anonymous namespace.
105 : :
106 : :
107 : :
108 : :
109 : : //===== TaskPanelFactory =======================================================
110 : :
111 : 16 : TaskPanelFactory::TaskPanelFactory (
112 : : const ::com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext>& rxContext)
113 : : : TaskPanelFactoryInterfaceBase(m_aMutex),
114 : 16 : mpViewShellBase(NULL)
115 : : {
116 : : (void)rxContext;
117 : 16 : }
118 : :
119 : :
120 : :
121 : :
122 [ + - ]: 16 : TaskPanelFactory::~TaskPanelFactory (void)
123 : : {
124 [ - + ]: 32 : }
125 : :
126 : :
127 : :
128 : :
129 : 16 : void SAL_CALL TaskPanelFactory::disposing (void)
130 : : {
131 : 16 : }
132 : :
133 : :
134 : :
135 : :
136 : : //===== XInitialization =======================================================
137 : :
138 : 16 : void SAL_CALL TaskPanelFactory::initialize(
139 : : const ::com::sun::star::uno::Sequence<com::sun::star::uno::Any>& aArguments)
140 : : throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
141 : : {
142 [ + - ]: 16 : if (aArguments.getLength() > 0)
143 : : {
144 : : try
145 : : {
146 : : // Get the XController from the first argument.
147 [ + - ]: 16 : Reference<frame::XController> xController (aArguments[0], UNO_QUERY_THROW);
148 : :
149 : : // Tunnel through the controller to obtain access to the ViewShellBase.
150 : : try
151 : : {
152 [ + - ]: 16 : Reference<lang::XUnoTunnel> xTunnel (xController, UNO_QUERY_THROW);
153 : : DrawController* pController
154 : : = reinterpret_cast<DrawController*>(
155 : : sal::static_int_cast<sal_uIntPtr>(
156 [ + - ][ + - ]: 16 : xTunnel->getSomething(DrawController::getUnoTunnelId())));
[ + - ]
157 [ + - ]: 16 : if (pController != NULL)
158 [ + - ][ # # ]: 16 : mpViewShellBase = pController->GetViewShellBase();
159 : :
160 : : }
161 [ # # ]: 0 : catch(RuntimeException&)
162 : : {}
163 : :
164 : :
165 [ + - ]: 16 : Reference<XControllerManager> xCM (xController, UNO_QUERY_THROW);
166 : : Reference<XConfigurationController> xCC (
167 [ + - ][ + - ]: 16 : xCM->getConfigurationController(), UNO_QUERY_THROW);
[ + - ]
168 [ + - ][ + - ]: 16 : xCC->addResourceFactory(FrameworkHelper::msMasterPagesTaskPanelURL, this);
[ + - ]
169 [ + - ][ + - ]: 16 : xCC->addResourceFactory(FrameworkHelper::msLayoutTaskPanelURL, this);
[ + - ]
170 [ + - ][ + - ]: 16 : xCC->addResourceFactory(FrameworkHelper::msTableDesignPanelURL, this);
[ + - ]
171 [ + - ][ + - ]: 16 : xCC->addResourceFactory(FrameworkHelper::msCustomAnimationTaskPanelURL, this);
[ + - ]
172 [ + - ][ + - ]: 16 : xCC->addResourceFactory(FrameworkHelper::msSlideTransitionTaskPanelURL, this);
[ # # ][ + - ]
173 : : }
174 : 0 : catch (RuntimeException&)
175 : : {
176 : : }
177 : : }
178 : 16 : }
179 : :
180 : :
181 : : //===== XResourceController ===================================================
182 : :
183 : : namespace
184 : : {
185 : 44 : void lcl_collectResourceURLs( const Reference< XResourceId >& i_rResourceId, ::std::vector< ::rtl::OUString >& o_rResourceURLs )
186 : : {
187 [ + - ]: 88 : ENSURE_OR_RETURN_VOID( i_rResourceId.is(), "illegal resource ID" );
188 [ + - ]: 44 : o_rResourceURLs.resize(0);
189 : :
190 : 44 : Reference< XResourceId > xResourceId( i_rResourceId );
191 [ + - ][ + - ]: 44 : ::rtl::OUString sResourceURL = xResourceId->getResourceURL();
192 [ + + ]: 176 : while ( !sResourceURL.isEmpty() )
193 : : {
194 [ + - ]: 132 : o_rResourceURLs.push_back( sResourceURL );
195 [ + - ][ + - ]: 132 : xResourceId = xResourceId->getAnchor();
[ + - ]
196 [ + - ][ + - ]: 132 : sResourceURL = xResourceId->getResourceURL();
197 : 44 : }
198 : : }
199 : : }
200 : :
201 : 22 : Reference<XResource> SAL_CALL TaskPanelFactory::createResource (
202 : : const Reference<XResourceId>& rxResourceId)
203 : : throw (RuntimeException, IllegalArgumentException, WrappedTargetException)
204 : : {
205 : 22 : Reference<XResource> xResource;
206 : :
207 [ - + ]: 22 : if ( ! rxResourceId.is())
208 [ # # ]: 0 : return NULL;
209 : :
210 [ + - ][ + - ]: 22 : OUString sResourceURL (rxResourceId->getResourceURL());
211 : :
212 [ + - ]: 22 : if ( sResourceURL.match( FrameworkHelper::msTaskPanelURLPrefix ) )
213 : : {
214 [ + - ]: 22 : toolpanel::PanelId ePanelId( toolpanel::GetStandardPanelId( sResourceURL ) );
215 : :
216 [ + - ][ + - ]: 22 : if ( ( ePanelId != toolpanel::PID_UNKNOWN ) && ( mpViewShellBase != NULL ) )
217 : : {
218 [ + - ]: 22 : ::boost::shared_ptr< FrameworkHelper > pFrameworkHelper( FrameworkHelper::Instance( *mpViewShellBase ) );
219 : :
220 : : // assume that the top-level anchor is the URL of the pane
221 [ + - ]: 22 : ::std::vector< ::rtl::OUString > aResourceURLs;
222 [ + - ]: 22 : lcl_collectResourceURLs( rxResourceId, aResourceURLs );
223 : :
224 : 22 : const ::rtl::OUString sPaneURL = aResourceURLs[ aResourceURLs.size() - 1 ];
225 [ + - ]: 22 : const ::boost::shared_ptr< ViewShell > pPaneViewShell( pFrameworkHelper->GetViewShell( sPaneURL ) );
226 : :
227 [ - + ]: 22 : toolpanel::ToolPanelViewShell* pToolPanel = dynamic_cast< toolpanel::ToolPanelViewShell* >( pPaneViewShell.get() );
228 [ + - ]: 22 : if ( pToolPanel != NULL )
229 [ + - ][ + - ]: 22 : xResource = new TaskPanelResource( rxResourceId );
[ + - ]
230 : :
231 [ + - ][ + - ]: 22 : OSL_POSTCOND( xResource.is(), "TaskPanelFactory::createResource: did not find the given resource!" );
232 : : }
233 : : }
234 : :
235 : 22 : return xResource;
236 : : }
237 : :
238 : :
239 : :
240 : :
241 : 22 : void SAL_CALL TaskPanelFactory::releaseResource (
242 : : const Reference<XResource>& rxResource)
243 : : throw (RuntimeException)
244 : : {
245 [ + - ]: 44 : ENSURE_OR_RETURN_VOID( rxResource.is(), "illegal resource" );
246 [ + - ][ + - ]: 22 : const Reference< XResourceId > xResourceId( rxResource->getResourceId(), UNO_SET_THROW );
[ + - ]
247 : :
248 : : // assume that the top-level anchor is the URL of the pane
249 [ + - ]: 22 : ::std::vector< ::rtl::OUString > aResourceURLs;
250 [ + - ]: 22 : lcl_collectResourceURLs( xResourceId, aResourceURLs );
251 : :
252 : : OSL_ENSURE( !aResourceURLs.empty(), "TaskPanelFactory::releaseResource: illegal resource/URL!" );
253 [ + - ]: 22 : if ( !aResourceURLs.empty() )
254 : : {
255 : 22 : const ::rtl::OUString sPaneURL = aResourceURLs[ aResourceURLs.size() - 1 ];
256 [ + - ]: 22 : ::boost::shared_ptr< FrameworkHelper > pFrameworkHelper( FrameworkHelper::Instance( *mpViewShellBase ) );
257 [ + - ]: 22 : const ::boost::shared_ptr< ViewShell > pPaneViewShell( pFrameworkHelper->GetViewShell( sPaneURL ) );
258 [ + + ]: 22 : if ( pPaneViewShell != NULL )
259 : : {
260 [ + - ][ + - ]: 6 : const ::rtl::OUString sPanelResourceURL( xResourceId->getResourceURL() );
261 [ + - ]: 6 : const toolpanel::PanelId ePanelId( toolpanel::GetStandardPanelId( sPanelResourceURL ) );
262 [ - + ]: 6 : toolpanel::ToolPanelViewShell* pToolPanel = dynamic_cast< toolpanel::ToolPanelViewShell* >( pPaneViewShell.get() );
263 : :
264 [ + - ][ + - ]: 6 : if ( ( ePanelId != toolpanel::PID_UNKNOWN )
265 : : && ( pToolPanel != NULL )
266 : : )
267 : : {
268 [ + - ]: 6 : pToolPanel->DeactivatePanel( sPanelResourceURL );
269 : : }
270 : : else
271 : : {
272 : : OSL_FAIL( "TaskPanelFactory::releaseResource: don't know what to do with this resource!" );
273 : 6 : }
274 [ + - ][ + - ]: 22 : }
275 : : }
276 : :
277 [ + - ]: 22 : Reference<XComponent> xComponent (rxResource, UNO_QUERY);
278 [ + - ]: 22 : if (xComponent.is())
279 [ + - ][ + - ]: 22 : xComponent->dispose();
280 : : }
281 : :
282 : :
283 : :
284 : :
285 : : //===== ToolPanelResource =====================================================
286 : :
287 : : namespace {
288 : :
289 : 22 : TaskPanelResource::TaskPanelResource (
290 : : const Reference<XResourceId>& rxResourceId)
291 : : : TaskPanelResourceInterfaceBase(m_aMutex),
292 : 22 : mxResourceId(rxResourceId)
293 : : {
294 : 22 : }
295 : :
296 : :
297 : :
298 : :
299 [ + - ]: 22 : TaskPanelResource::~TaskPanelResource (void)
300 : : {
301 [ - + ]: 44 : }
302 : :
303 : :
304 : :
305 : :
306 : 22 : void SAL_CALL TaskPanelResource::disposing ()
307 : : {
308 : 22 : }
309 : :
310 : :
311 : :
312 : :
313 : 44 : Reference<XResourceId> SAL_CALL TaskPanelResource::getResourceId ()
314 : : throw (css::uno::RuntimeException)
315 : : {
316 : 44 : return mxResourceId;
317 : : }
318 : :
319 : : } // end of anonymous namespace
320 : :
321 : : } } // end of namespace sd::framework
322 : :
323 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|