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