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 <osl/mutex.hxx>
21 : #include <toolkit/helper/vclunohelper.hxx>
22 :
23 : #include <osl/thread.h>
24 : #include <cppuhelper/factory.hxx>
25 : #include <cppuhelper/typeprovider.hxx>
26 : #include <cppuhelper/component.hxx>
27 : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
28 : #include <com/sun/star/frame/Desktop.hpp>
29 : #include <com/sun/star/frame/XTerminateListener.hpp>
30 : #include <cppuhelper/implbase4.hxx>
31 : #include <cppuhelper/supportsservice.hxx>
32 : #include <com/sun/star/lang/XServiceInfo.hpp>
33 : #include <com/sun/star/lang/XInitialization.hpp>
34 : #include <com/sun/star/awt/XWindow.hpp>
35 : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
36 : #include <com/sun/star/beans/PropertyValue.hpp>
37 : #include <tools/resmgr.hxx>
38 : #include <vcl/svapp.hxx>
39 : #include <vcl/settings.hxx>
40 : #include <rtl/instance.hxx>
41 : #include <comphelper/processfactory.hxx>
42 :
43 : #include <svl/solar.hrc>
44 :
45 : #include "xmlfiltersettingsdialog.hxx"
46 :
47 : using namespace ::rtl;
48 : using namespace ::cppu;
49 : using namespace ::osl;
50 : using namespace ::com::sun::star::uno;
51 : using namespace ::com::sun::star::lang;
52 : using namespace ::com::sun::star::beans;
53 : using namespace ::com::sun::star::registry;
54 : using namespace ::com::sun::star::frame;
55 :
56 :
57 2 : class XMLFilterDialogComponentBase
58 : {
59 : protected:
60 : ::osl::Mutex maMutex;
61 : };
62 :
63 :
64 : class XMLFilterDialogComponent : public XMLFilterDialogComponentBase,
65 : public OComponentHelper,
66 : public ::com::sun::star::ui::dialogs::XExecutableDialog,
67 : public XServiceInfo,
68 : public XInitialization,
69 : public XTerminateListener
70 : {
71 : public:
72 : XMLFilterDialogComponent( const Reference< XComponentContext >& rxContext );
73 : virtual ~XMLFilterDialogComponent();
74 :
75 : protected:
76 : // XInterface
77 : virtual Any SAL_CALL queryInterface( const Type& aType ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
78 : virtual Any SAL_CALL queryAggregation( Type const & rType ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
79 : virtual void SAL_CALL acquire() throw () SAL_OVERRIDE;
80 : virtual void SAL_CALL release() throw () SAL_OVERRIDE;
81 :
82 : // XTypeProvider
83 : virtual Sequence< sal_Int8 > SAL_CALL getImplementationId() throw(RuntimeException, std::exception) SAL_OVERRIDE;
84 : virtual Sequence< Type > SAL_CALL getTypes() throw (RuntimeException, std::exception) SAL_OVERRIDE;
85 :
86 : // XServiceInfo
87 : virtual OUString SAL_CALL getImplementationName() throw(com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
88 : virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) throw(RuntimeException, std::exception) SAL_OVERRIDE;
89 : virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
90 :
91 : // XExecutableDialog
92 : virtual void SAL_CALL setTitle( const OUString& aTitle ) throw(RuntimeException, std::exception) SAL_OVERRIDE;
93 : virtual sal_Int16 SAL_CALL execute( ) throw(RuntimeException, std::exception) SAL_OVERRIDE;
94 :
95 : // XInitialization
96 : virtual void SAL_CALL initialize( const Sequence< Any >& aArguments ) throw(Exception, RuntimeException, std::exception) SAL_OVERRIDE;
97 :
98 : // XTerminateListener
99 : virtual void SAL_CALL queryTermination( const EventObject& Event ) throw (TerminationVetoException, RuntimeException, std::exception) SAL_OVERRIDE;
100 : virtual void SAL_CALL notifyTermination( const EventObject& Event ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
101 : virtual void SAL_CALL disposing( const EventObject& Source ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
102 :
103 : /** Called in dispose method after the listeners were notified.
104 : */
105 : virtual void SAL_CALL disposing() SAL_OVERRIDE;
106 :
107 : private:
108 : com::sun::star::uno::Reference<com::sun::star::awt::XWindow> mxParent; /// parent window
109 : com::sun::star::uno::Reference< XComponentContext > mxContext;
110 :
111 : XMLFilterSettingsDialog* mpDialog;
112 : };
113 :
114 :
115 :
116 : namespace
117 : {
118 : static ResMgr* pXSLTResMgr = NULL;
119 : }
120 :
121 0 : ResMgr* getXSLTDialogResMgr()
122 : {
123 0 : return pXSLTResMgr;
124 : }
125 :
126 1 : XMLFilterDialogComponent::XMLFilterDialogComponent( const com::sun::star::uno::Reference< XComponentContext >& rxContext ) :
127 : OComponentHelper( maMutex ),
128 : mxContext( rxContext ),
129 1 : mpDialog( NULL )
130 : {
131 1 : Reference< XDesktop2 > xDesktop = Desktop::create( rxContext );
132 2 : Reference< XTerminateListener > xListener( this );
133 2 : xDesktop->addTerminateListener( xListener );
134 1 : }
135 :
136 :
137 :
138 2 : XMLFilterDialogComponent::~XMLFilterDialogComponent()
139 : {
140 2 : }
141 :
142 :
143 :
144 : // XInterface
145 4 : Any SAL_CALL XMLFilterDialogComponent::queryInterface( const Type& aType ) throw (RuntimeException, std::exception)
146 : {
147 4 : return OComponentHelper::queryInterface( aType );
148 : }
149 :
150 :
151 :
152 4 : Any SAL_CALL XMLFilterDialogComponent::queryAggregation( Type const & rType ) throw (RuntimeException, std::exception)
153 : {
154 4 : if (rType == ::getCppuType( (Reference< ::com::sun::star::ui::dialogs::XExecutableDialog > const *)0 ))
155 : {
156 0 : void * p = static_cast< ::com::sun::star::ui::dialogs::XExecutableDialog * >( this );
157 0 : return Any( &p, rType );
158 : }
159 4 : else if (rType == ::getCppuType( (Reference< XServiceInfo > const *)0 ))
160 : {
161 1 : void * p = static_cast< XServiceInfo * >( this );
162 1 : return Any( &p, rType );
163 : }
164 3 : else if (rType == ::getCppuType( (Reference< XInitialization > const *)0 ))
165 : {
166 0 : void * p = static_cast< XInitialization * >( this );
167 0 : return Any( &p, rType );
168 : }
169 3 : else if (rType == ::getCppuType( (Reference< XTerminateListener > const *)0 ))
170 : {
171 0 : void * p = static_cast< XTerminateListener * >( this );
172 0 : return Any( &p, rType );
173 : }
174 3 : return OComponentHelper::queryAggregation( rType );
175 : }
176 :
177 :
178 :
179 13 : void SAL_CALL XMLFilterDialogComponent::acquire() throw ()
180 : {
181 13 : OComponentHelper::acquire();
182 13 : }
183 :
184 :
185 :
186 13 : void SAL_CALL XMLFilterDialogComponent::release() throw ()
187 : {
188 13 : OComponentHelper::release();
189 13 : }
190 :
191 :
192 :
193 2 : OUString XMLFilterDialogComponent_getImplementationName() throw ( RuntimeException )
194 : {
195 2 : return OUString( "com.sun.star.comp.ui.XSLTFilterDialog" );
196 : }
197 :
198 1 : Sequence< OUString > SAL_CALL XMLFilterDialogComponent_getSupportedServiceNames() throw ( RuntimeException )
199 : {
200 1 : Sequence< OUString > aSupported(1);
201 1 : aSupported[0] = "com.sun.star.ui.dialogs.XSLTFilterDialog";
202 1 : return aSupported;
203 : }
204 :
205 1 : Reference< XInterface > SAL_CALL XMLFilterDialogComponent_createInstance( const Reference< XMultiServiceFactory > & rSMgr) throw ( Exception )
206 : {
207 1 : return (OWeakObject*)new XMLFilterDialogComponent( comphelper::getComponentContext(rSMgr) );
208 : }
209 :
210 1 : OUString SAL_CALL XMLFilterDialogComponent::getImplementationName() throw(com::sun::star::uno::RuntimeException, std::exception)
211 : {
212 1 : return XMLFilterDialogComponent_getImplementationName();
213 : }
214 :
215 : namespace { struct lcl_ImplId : public rtl::Static< ::cppu::OImplementationId, lcl_ImplId > {}; }
216 :
217 0 : Sequence< sal_Int8 > SAL_CALL XMLFilterDialogComponent::getImplementationId( void ) throw( RuntimeException, std::exception )
218 : {
219 0 : return css::uno::Sequence<sal_Int8>();
220 : }
221 :
222 :
223 :
224 : namespace
225 : {
226 0 : class DialogComponentTypes
227 : {
228 : private:
229 : OTypeCollection m_aTypes;
230 : public:
231 0 : DialogComponentTypes() :
232 : m_aTypes(
233 0 : ::getCppuType( (const Reference< XComponent > *)0 ),
234 0 : ::getCppuType( (const Reference< XTypeProvider > *)0 ),
235 0 : ::getCppuType( (const Reference< XAggregation > *)0 ),
236 0 : ::getCppuType( (const Reference< XWeak > *)0 ),
237 0 : ::getCppuType( (const Reference< XServiceInfo > *)0 ),
238 0 : ::getCppuType( (const Reference< XInitialization > *)0 ),
239 0 : ::getCppuType( (const Reference< XTerminateListener > *)0 ),
240 0 : ::getCppuType( (const Reference< ::com::sun::star::ui::dialogs::XExecutableDialog > *)0 ))
241 : {
242 0 : }
243 0 : OTypeCollection& getTypeCollection() { return m_aTypes; }
244 : };
245 :
246 : struct theDialogComponentTypes : rtl::Static<DialogComponentTypes, theDialogComponentTypes> {};
247 : }
248 :
249 0 : Sequence< Type > XMLFilterDialogComponent::getTypes() throw (RuntimeException, std::exception)
250 : {
251 0 : return theDialogComponentTypes::get().getTypeCollection().getTypes();
252 : }
253 :
254 0 : Sequence< OUString > SAL_CALL XMLFilterDialogComponent::getSupportedServiceNames() throw(com::sun::star::uno::RuntimeException, std::exception)
255 : {
256 0 : return XMLFilterDialogComponent_getSupportedServiceNames();
257 : }
258 :
259 0 : sal_Bool SAL_CALL XMLFilterDialogComponent::supportsService(const OUString& ServiceName) throw(RuntimeException, std::exception)
260 : {
261 0 : return cppu::supportsService( this, ServiceName );
262 : }
263 :
264 : /** Called in dispose method after the listeners were notified.
265 : */
266 1 : void SAL_CALL XMLFilterDialogComponent::disposing()
267 : {
268 1 : ::SolarMutexGuard aGuard;
269 :
270 1 : if( mpDialog )
271 : {
272 0 : delete mpDialog;
273 0 : mpDialog = NULL;
274 : }
275 :
276 1 : if (pXSLTResMgr)
277 : {
278 0 : delete pXSLTResMgr;
279 0 : pXSLTResMgr = NULL;
280 1 : }
281 1 : }
282 :
283 :
284 :
285 : // XTerminateListener
286 0 : void SAL_CALL XMLFilterDialogComponent::queryTermination( const EventObject& /* Event */ ) throw (TerminationVetoException, RuntimeException, std::exception)
287 : {
288 0 : ::SolarMutexGuard aGuard;
289 :
290 0 : if (!mpDialog)
291 0 : return;
292 :
293 : // we will never give a veto here
294 0 : if (!mpDialog->isClosable())
295 : {
296 0 : mpDialog->ToTop();
297 : throw TerminationVetoException(
298 : OUString("The office cannot be closed while the XMLFilterDialog is running"),
299 0 : Reference<XInterface>(static_cast<XTerminateListener*>(this), UNO_QUERY));
300 : }
301 : else
302 0 : mpDialog->Close();
303 : }
304 :
305 :
306 :
307 0 : void SAL_CALL XMLFilterDialogComponent::notifyTermination( const EventObject& /* Event */ ) throw (RuntimeException, std::exception)
308 : {
309 : // we are going down, so dispose us!
310 0 : dispose();
311 0 : }
312 :
313 0 : void SAL_CALL XMLFilterDialogComponent::disposing( const EventObject& /* Source */ ) throw (RuntimeException, std::exception)
314 : {
315 0 : }
316 :
317 :
318 0 : void SAL_CALL XMLFilterDialogComponent::setTitle( const OUString& /* _rTitle */ ) throw(RuntimeException, std::exception)
319 : {
320 0 : }
321 :
322 :
323 0 : sal_Int16 SAL_CALL XMLFilterDialogComponent::execute( ) throw(RuntimeException, std::exception)
324 : {
325 0 : ::SolarMutexGuard aGuard;
326 :
327 0 : if( NULL == pXSLTResMgr )
328 : {
329 0 : pXSLTResMgr = ResMgr::CreateResMgr( "xsltdlg", Application::GetSettings().GetUILanguageTag() );
330 : }
331 :
332 0 : if( NULL == mpDialog )
333 : {
334 0 : Window* pParent = DIALOG_NO_PARENT;
335 0 : if (mxParent.is())
336 0 : pParent = VCLUnoHelper::GetWindow(mxParent);
337 :
338 0 : Reference< XComponent > xComp( this );
339 0 : mpDialog = new XMLFilterSettingsDialog(pParent, mxContext);
340 0 : mpDialog->Execute();
341 : }
342 0 : else if( !mpDialog->IsVisible() )
343 : {
344 0 : mpDialog->Execute();
345 : }
346 0 : mpDialog->ToTop();
347 :
348 0 : return 0;
349 : }
350 :
351 :
352 0 : void SAL_CALL XMLFilterDialogComponent::initialize( const Sequence< Any >& aArguments ) throw(Exception, RuntimeException, std::exception)
353 : {
354 0 : const Any* pArguments = aArguments.getConstArray();
355 0 : for(sal_Int32 i=0; i<aArguments.getLength(); ++i, ++pArguments)
356 : {
357 0 : PropertyValue aProperty;
358 0 : if(*pArguments >>= aProperty)
359 : {
360 0 : if( aProperty.Name == "ParentWindow" )
361 : {
362 0 : aProperty.Value >>= mxParent;
363 : }
364 : }
365 0 : }
366 0 : }
367 :
368 :
369 : extern "C"
370 : {
371 1 : SAL_DLLPUBLIC_EXPORT void * SAL_CALL xsltdlg_component_getFactory(
372 : const sal_Char * pImplName, void * pServiceManager, void * /* pRegistryKey */ )
373 : {
374 1 : void * pRet = 0;
375 :
376 1 : if( pServiceManager )
377 : {
378 1 : Reference< XSingleServiceFactory > xFactory;
379 :
380 2 : OUString implName = OUString::createFromAscii( pImplName );
381 1 : if ( implName.equals(XMLFilterDialogComponent_getImplementationName()) )
382 : {
383 2 : xFactory = createOneInstanceFactory(
384 : reinterpret_cast< XMultiServiceFactory * >( pServiceManager ),
385 : OUString::createFromAscii( pImplName ),
386 1 : XMLFilterDialogComponent_createInstance, XMLFilterDialogComponent_getSupportedServiceNames() );
387 :
388 : }
389 :
390 1 : if (xFactory.is())
391 : {
392 1 : xFactory->acquire();
393 1 : pRet = xFactory.get();
394 1 : }
395 : }
396 :
397 1 : return pRet;
398 : }
399 3 : }
400 :
401 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|