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 : #include "TaskPanelFactory.hxx"
21 : #include "taskpane/ToolPanelViewShell.hxx"
22 : #include "DrawController.hxx"
23 : #include "framework/FrameworkHelper.hxx"
24 : #include <cppuhelper/compbase1.hxx>
25 : #include <tools/diagnose_ex.h>
26 :
27 : using namespace ::com::sun::star;
28 : using namespace ::com::sun::star::uno;
29 : using namespace ::com::sun::star::lang;
30 : using namespace ::com::sun::star::drawing::framework;
31 :
32 : using ::sd::framework::FrameworkHelper;
33 :
34 : namespace sd { namespace framework {
35 :
36 9 : Reference<XInterface> SAL_CALL TaskPanelFactory_createInstance (
37 : const Reference<XComponentContext>& rxContext)
38 : {
39 9 : return Reference<XInterface>(static_cast<XWeak*>(new TaskPanelFactory(rxContext)));
40 : }
41 :
42 :
43 :
44 :
45 13 : OUString TaskPanelFactory_getImplementationName (void) throw(RuntimeException)
46 : {
47 13 : return OUString("com.sun.star.comp.Draw.framework.TaskPanelFactory");
48 : }
49 :
50 :
51 :
52 :
53 3 : Sequence<OUString> SAL_CALL TaskPanelFactory_getSupportedServiceNames (void)
54 : throw (RuntimeException)
55 : {
56 3 : const OUString sServiceName("com.sun.star.drawing.framework.TaskPanelFactory");
57 3 : return Sequence<OUString>(&sServiceName, 1);
58 : }
59 :
60 :
61 :
62 :
63 : //===== ToolPanelResource =====================================================
64 :
65 : namespace {
66 :
67 : typedef ::cppu::WeakComponentImplHelper1 <
68 : css::drawing::framework::XResource
69 : > TaskPanelResourceInterfaceBase;
70 :
71 : class TaskPanelResource
72 : : private ::cppu::BaseMutex,
73 : public TaskPanelResourceInterfaceBase
74 : {
75 : public:
76 : TaskPanelResource (
77 : const Reference<XResourceId>& rxResourceId );
78 : virtual ~TaskPanelResource ();
79 :
80 : virtual void SAL_CALL disposing ();
81 :
82 : // XResource
83 :
84 : virtual Reference<XResourceId> SAL_CALL getResourceId (void)
85 : throw (css::uno::RuntimeException);
86 :
87 21 : virtual sal_Bool SAL_CALL isAnchorOnly () throw (RuntimeException)
88 21 : { return false; }
89 :
90 : private:
91 : const Reference<XResourceId> mxResourceId;
92 : };
93 :
94 : } // end of anonymous namespace.
95 :
96 :
97 :
98 :
99 : //===== TaskPanelFactory =======================================================
100 :
101 9 : TaskPanelFactory::TaskPanelFactory (
102 : const ::com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext>& rxContext)
103 : : TaskPanelFactoryInterfaceBase(m_aMutex),
104 9 : mpViewShellBase(NULL)
105 : {
106 : (void)rxContext;
107 9 : }
108 :
109 :
110 :
111 :
112 18 : TaskPanelFactory::~TaskPanelFactory (void)
113 : {
114 18 : }
115 :
116 :
117 :
118 :
119 9 : void SAL_CALL TaskPanelFactory::disposing (void)
120 : {
121 9 : }
122 :
123 :
124 :
125 :
126 : //===== XInitialization =======================================================
127 :
128 9 : void SAL_CALL TaskPanelFactory::initialize(
129 : const ::com::sun::star::uno::Sequence<com::sun::star::uno::Any>& aArguments)
130 : throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
131 : {
132 9 : if (aArguments.getLength() > 0)
133 : {
134 : try
135 : {
136 : // Get the XController from the first argument.
137 9 : Reference<frame::XController> xController (aArguments[0], UNO_QUERY_THROW);
138 :
139 : // Tunnel through the controller to obtain access to the ViewShellBase.
140 : try
141 : {
142 9 : Reference<lang::XUnoTunnel> xTunnel (xController, UNO_QUERY_THROW);
143 : DrawController* pController
144 : = reinterpret_cast<DrawController*>(
145 : sal::static_int_cast<sal_uIntPtr>(
146 9 : xTunnel->getSomething(DrawController::getUnoTunnelId())));
147 9 : if (pController != NULL)
148 9 : mpViewShellBase = pController->GetViewShellBase();
149 :
150 : }
151 0 : catch(RuntimeException&)
152 : {}
153 :
154 18 : Reference<XControllerManager> xCM (xController, UNO_QUERY_THROW);
155 : Reference<XConfigurationController> xCC (
156 18 : xCM->getConfigurationController(), UNO_QUERY_THROW);
157 9 : xCC->addResourceFactory(FrameworkHelper::msMasterPagesTaskPanelURL, this);
158 9 : xCC->addResourceFactory(FrameworkHelper::msLayoutTaskPanelURL, this);
159 9 : xCC->addResourceFactory(FrameworkHelper::msTableDesignPanelURL, this);
160 9 : xCC->addResourceFactory(FrameworkHelper::msCustomAnimationTaskPanelURL, this);
161 18 : xCC->addResourceFactory(FrameworkHelper::msSlideTransitionTaskPanelURL, this);
162 : }
163 0 : catch (RuntimeException&)
164 : {
165 : }
166 : }
167 9 : }
168 :
169 :
170 : //===== XResourceController ===================================================
171 :
172 : namespace
173 : {
174 24 : void lcl_collectResourceURLs( const Reference< XResourceId >& i_rResourceId, ::std::vector< OUString >& o_rResourceURLs )
175 : {
176 48 : ENSURE_OR_RETURN_VOID( i_rResourceId.is(), "illegal resource ID" );
177 24 : o_rResourceURLs.resize(0);
178 :
179 24 : Reference< XResourceId > xResourceId( i_rResourceId );
180 48 : OUString sResourceURL = xResourceId->getResourceURL();
181 120 : while ( !sResourceURL.isEmpty() )
182 : {
183 72 : o_rResourceURLs.push_back( sResourceURL );
184 72 : xResourceId = xResourceId->getAnchor();
185 72 : sResourceURL = xResourceId->getResourceURL();
186 24 : }
187 : }
188 : }
189 :
190 12 : Reference<XResource> SAL_CALL TaskPanelFactory::createResource (
191 : const Reference<XResourceId>& rxResourceId)
192 : throw (RuntimeException, IllegalArgumentException, WrappedTargetException)
193 : {
194 12 : Reference<XResource> xResource;
195 :
196 12 : if ( ! rxResourceId.is())
197 0 : return NULL;
198 :
199 24 : OUString sResourceURL (rxResourceId->getResourceURL());
200 :
201 12 : if ( sResourceURL.match( FrameworkHelper::msTaskPanelURLPrefix ) )
202 : {
203 12 : toolpanel::PanelId ePanelId( toolpanel::GetStandardPanelId( sResourceURL ) );
204 :
205 12 : if ( ( ePanelId != toolpanel::PID_UNKNOWN ) && ( mpViewShellBase != NULL ) )
206 : {
207 12 : ::boost::shared_ptr< FrameworkHelper > pFrameworkHelper( FrameworkHelper::Instance( *mpViewShellBase ) );
208 :
209 : // assume that the top-level anchor is the URL of the pane
210 24 : ::std::vector< OUString > aResourceURLs;
211 12 : lcl_collectResourceURLs( rxResourceId, aResourceURLs );
212 :
213 24 : const OUString sPaneURL = aResourceURLs[ aResourceURLs.size() - 1 ];
214 24 : const ::boost::shared_ptr< ViewShell > pPaneViewShell( pFrameworkHelper->GetViewShell( sPaneURL ) );
215 :
216 12 : toolpanel::ToolPanelViewShell* pToolPanel = dynamic_cast< toolpanel::ToolPanelViewShell* >( pPaneViewShell.get() );
217 12 : if ( pToolPanel != NULL )
218 12 : xResource = new TaskPanelResource( rxResourceId );
219 :
220 12 : OSL_POSTCOND( xResource.is(), "TaskPanelFactory::createResource: did not find the given resource!");
221 : }
222 : }
223 :
224 24 : return xResource;
225 : }
226 :
227 :
228 :
229 :
230 12 : void SAL_CALL TaskPanelFactory::releaseResource (
231 : const Reference<XResource>& rxResource)
232 : throw (RuntimeException)
233 : {
234 24 : ENSURE_OR_RETURN_VOID( rxResource.is(), "illegal resource" );
235 12 : const Reference< XResourceId > xResourceId( rxResource->getResourceId(), UNO_SET_THROW );
236 :
237 : // assume that the top-level anchor is the URL of the pane
238 24 : ::std::vector< OUString > aResourceURLs;
239 12 : lcl_collectResourceURLs( xResourceId, aResourceURLs );
240 :
241 : OSL_ENSURE( !aResourceURLs.empty(), "TaskPanelFactory::releaseResource: illegal resource/URL!" );
242 12 : if ( !aResourceURLs.empty() )
243 : {
244 12 : const OUString sPaneURL = aResourceURLs[ aResourceURLs.size() - 1 ];
245 24 : ::boost::shared_ptr< FrameworkHelper > pFrameworkHelper( FrameworkHelper::Instance( *mpViewShellBase ) );
246 24 : const ::boost::shared_ptr< ViewShell > pPaneViewShell( pFrameworkHelper->GetViewShell( sPaneURL ) );
247 12 : if ( pPaneViewShell != 0 )
248 : {
249 3 : const OUString sPanelResourceURL( xResourceId->getResourceURL() );
250 3 : const toolpanel::PanelId ePanelId( toolpanel::GetStandardPanelId( sPanelResourceURL ) );
251 3 : toolpanel::ToolPanelViewShell* pToolPanel = dynamic_cast< toolpanel::ToolPanelViewShell* >( pPaneViewShell.get() );
252 :
253 3 : if ( ( ePanelId != toolpanel::PID_UNKNOWN )
254 3 : && ( pToolPanel != NULL )
255 : )
256 : {
257 3 : pToolPanel->DeactivatePanel( sPanelResourceURL );
258 : }
259 : else
260 : {
261 : OSL_FAIL( "TaskPanelFactory::releaseResource: don't know what to do with this resource!" );
262 3 : }
263 12 : }
264 : }
265 :
266 24 : Reference<XComponent> xComponent (rxResource, UNO_QUERY);
267 12 : if (xComponent.is())
268 24 : xComponent->dispose();
269 : }
270 :
271 :
272 :
273 :
274 : //===== ToolPanelResource =====================================================
275 :
276 : namespace {
277 :
278 12 : TaskPanelResource::TaskPanelResource (
279 : const Reference<XResourceId>& rxResourceId)
280 : : TaskPanelResourceInterfaceBase(m_aMutex),
281 12 : mxResourceId(rxResourceId)
282 : {
283 12 : }
284 :
285 :
286 :
287 :
288 24 : TaskPanelResource::~TaskPanelResource (void)
289 : {
290 24 : }
291 :
292 :
293 :
294 :
295 12 : void SAL_CALL TaskPanelResource::disposing ()
296 : {
297 12 : }
298 :
299 :
300 :
301 :
302 24 : Reference<XResourceId> SAL_CALL TaskPanelResource::getResourceId ()
303 : throw (css::uno::RuntimeException)
304 : {
305 24 : return mxResourceId;
306 : }
307 :
308 : } // end of anonymous namespace
309 :
310 33 : } } // end of namespace sd::framework
311 :
312 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|