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