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