1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <osl/mutex.hxx>
21 #include <toolkit/helper/vclunohelper.hxx>
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>
41 #include <svl/solar.hrc>
43 #include "xmlfiltersettingsdialog.hxx"
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
;
55 class XMLFilterDialogComponentBase
62 class XMLFilterDialogComponent
: public XMLFilterDialogComponentBase
,
63 public OComponentHelper
,
64 public ::com::sun::star::ui::dialogs::XExecutableDialog
,
66 public XInitialization
,
67 public XTerminateListener
70 XMLFilterDialogComponent( const Reference
< XMultiServiceFactory
>& rxMSF
);
71 virtual ~XMLFilterDialogComponent();
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 ();
81 virtual Sequence
< sal_Int8
> SAL_CALL
getImplementationId() throw(RuntimeException
);
82 virtual Sequence
< Type
> SAL_CALL
getTypes() throw (RuntimeException
);
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
);
90 virtual void SAL_CALL
setTitle( const OUString
& aTitle
) throw(RuntimeException
);
91 virtual sal_Int16 SAL_CALL
execute( ) throw(RuntimeException
);
94 virtual void SAL_CALL
initialize( const Sequence
< Any
>& aArguments
) throw(Exception
, RuntimeException
);
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
);
101 /** Called in dispose method after the listeners were notified.
103 virtual void SAL_CALL
disposing();
106 com::sun::star::uno::Reference
<com::sun::star::awt::XWindow
> mxParent
; /// parent window
107 com::sun::star::uno::Reference
< XMultiServiceFactory
> mxMSF
;
109 XMLFilterSettingsDialog
* mpDialog
;
112 //-------------------------------------------------------------------------
116 static ResMgr
* pXSLTResMgr
= NULL
;
119 ResMgr
* getXSLTDialogResMgr()
124 XMLFilterDialogComponent::XMLFilterDialogComponent( const com::sun::star::uno::Reference
< XMultiServiceFactory
>& rxMSF
) :
125 OComponentHelper( maMutex
),
129 Reference
< XDesktop2
> xDesktop
= Desktop::create( comphelper::getComponentContext(mxMSF
) );
130 Reference
< XTerminateListener
> xListener( this );
131 xDesktop
->addTerminateListener( xListener
);
134 //-------------------------------------------------------------------------
136 XMLFilterDialogComponent::~XMLFilterDialogComponent()
140 //-------------------------------------------------------------------------
143 Any SAL_CALL
XMLFilterDialogComponent::queryInterface( const Type
& aType
) throw (RuntimeException
)
145 return OComponentHelper::queryInterface( aType
);
148 //-------------------------------------------------------------------------
150 Any SAL_CALL
XMLFilterDialogComponent::queryAggregation( Type
const & rType
) throw (RuntimeException
)
152 if (rType
== ::getCppuType( (Reference
< ::com::sun::star::ui::dialogs::XExecutableDialog
> const *)0 ))
154 void * p
= static_cast< ::com::sun::star::ui::dialogs::XExecutableDialog
* >( this );
155 return Any( &p
, rType
);
157 else if (rType
== ::getCppuType( (Reference
< XServiceInfo
> const *)0 ))
159 void * p
= static_cast< XServiceInfo
* >( this );
160 return Any( &p
, rType
);
162 else if (rType
== ::getCppuType( (Reference
< XInitialization
> const *)0 ))
164 void * p
= static_cast< XInitialization
* >( this );
165 return Any( &p
, rType
);
167 else if (rType
== ::getCppuType( (Reference
< XTerminateListener
> const *)0 ))
169 void * p
= static_cast< XTerminateListener
* >( this );
170 return Any( &p
, rType
);
172 return OComponentHelper::queryAggregation( rType
);
175 //-------------------------------------------------------------------------
177 void SAL_CALL
XMLFilterDialogComponent::acquire() throw ()
179 OComponentHelper::acquire();
182 //-------------------------------------------------------------------------
184 void SAL_CALL
XMLFilterDialogComponent::release() throw ()
186 OComponentHelper::release();
189 //-------------------------------------------------------------------------
191 OUString
XMLFilterDialogComponent_getImplementationName() throw ( RuntimeException
)
193 return OUString( "com.sun.star.comp.ui.XSLTFilterDialog" );
196 //-------------------------------------------------------------------------
198 Sequence
< OUString
> SAL_CALL
XMLFilterDialogComponent_getSupportedServiceNames() throw ( RuntimeException
)
200 Sequence
< OUString
> aSupported(1);
201 aSupported
[0] = OUString( "com.sun.star.ui.dialogs.XSLTFilterDialog" );
205 //-------------------------------------------------------------------------
207 sal_Bool SAL_CALL
XMLFilterDialogComponent_supportsService( const OUString
& ServiceName
) throw ( RuntimeException
)
209 Sequence
< OUString
> aSupported(XMLFilterDialogComponent_getSupportedServiceNames());
210 const OUString
* pArray
= aSupported
.getConstArray();
211 for (sal_Int32 i
= 0; i
< aSupported
.getLength(); ++i
, ++pArray
)
212 if (pArray
->equals(ServiceName
))
217 //-------------------------------------------------------------------------
219 Reference
< XInterface
> SAL_CALL
XMLFilterDialogComponent_createInstance( const Reference
< XMultiServiceFactory
> & rSMgr
) throw ( Exception
)
221 return (OWeakObject
*)new XMLFilterDialogComponent( rSMgr
);
224 //-------------------------------------------------------------------------
225 OUString SAL_CALL
XMLFilterDialogComponent::getImplementationName() throw(com::sun::star::uno::RuntimeException
)
227 return XMLFilterDialogComponent_getImplementationName();
230 //-------------------------------------------------------------------------
232 namespace { struct lcl_ImplId
: public rtl::Static
< ::cppu::OImplementationId
, lcl_ImplId
> {}; }
234 Sequence
< sal_Int8
> SAL_CALL
XMLFilterDialogComponent::getImplementationId( void ) throw( RuntimeException
)
236 ::cppu::OImplementationId
&rID
= lcl_ImplId::get();
237 return rID
.getImplementationId();
240 //-------------------------------------------------------------------------
244 class DialogComponentTypes
247 OTypeCollection m_aTypes
;
249 DialogComponentTypes() :
251 ::getCppuType( (const Reference
< XComponent
> *)0 ),
252 ::getCppuType( (const Reference
< XTypeProvider
> *)0 ),
253 ::getCppuType( (const Reference
< XAggregation
> *)0 ),
254 ::getCppuType( (const Reference
< XWeak
> *)0 ),
255 ::getCppuType( (const Reference
< XServiceInfo
> *)0 ),
256 ::getCppuType( (const Reference
< XInitialization
> *)0 ),
257 ::getCppuType( (const Reference
< XTerminateListener
> *)0 ),
258 ::getCppuType( (const Reference
< ::com::sun::star::ui::dialogs::XExecutableDialog
> *)0 ))
261 OTypeCollection
& getTypeCollection() { return m_aTypes
; }
264 struct theDialogComponentTypes
: rtl::Static
<DialogComponentTypes
, theDialogComponentTypes
> {};
267 Sequence
< Type
> XMLFilterDialogComponent::getTypes() throw (RuntimeException
)
269 return theDialogComponentTypes::get().getTypeCollection().getTypes();
272 //-------------------------------------------------------------------------
274 Sequence
< OUString
> SAL_CALL
XMLFilterDialogComponent::getSupportedServiceNames() throw(com::sun::star::uno::RuntimeException
)
276 return XMLFilterDialogComponent_getSupportedServiceNames();
279 //-------------------------------------------------------------------------
280 sal_Bool SAL_CALL
XMLFilterDialogComponent::supportsService(const OUString
& ServiceName
) throw(RuntimeException
)
282 return XMLFilterDialogComponent_supportsService( ServiceName
);
285 //-------------------------------------------------------------------------
287 /** Called in dispose method after the listeners were notified.
289 void SAL_CALL
XMLFilterDialogComponent::disposing()
291 ::SolarMutexGuard aGuard
;
306 //-------------------------------------------------------------------------
308 // XTerminateListener
309 void SAL_CALL
XMLFilterDialogComponent::queryTermination( const EventObject
& /* Event */ ) throw (TerminationVetoException
, RuntimeException
)
311 ::SolarMutexGuard aGuard
;
316 // we will never give a veto here
317 if (!mpDialog
->isClosable())
320 throw TerminationVetoException(
321 OUString("The office cannot be closed while the XMLFilterDialog is running"),
322 Reference
<XInterface
>(static_cast<XTerminateListener
*>(this), UNO_QUERY
));
328 //-------------------------------------------------------------------------
330 void SAL_CALL
XMLFilterDialogComponent::notifyTermination( const EventObject
& /* Event */ ) throw (RuntimeException
)
332 // we are going down, so dispose us!
336 void SAL_CALL
XMLFilterDialogComponent::disposing( const EventObject
& /* Source */ ) throw (RuntimeException
)
340 //-------------------------------------------------------------------------
341 void SAL_CALL
XMLFilterDialogComponent::setTitle( const OUString
& /* _rTitle */ ) throw(RuntimeException
)
345 //-------------------------------------------------------------------------
346 sal_Int16 SAL_CALL
XMLFilterDialogComponent::execute( ) throw(RuntimeException
)
348 ::SolarMutexGuard aGuard
;
350 if( NULL
== pXSLTResMgr
)
352 pXSLTResMgr
= ResMgr::CreateResMgr( "xsltdlg", Application::GetSettings().GetUILanguageTag() );
355 if( NULL
== mpDialog
)
357 Window
* pParent
= DIALOG_NO_PARENT
;
359 pParent
= VCLUnoHelper::GetWindow(mxParent
);
361 Reference
< XComponent
> xComp( this );
362 mpDialog
= new XMLFilterSettingsDialog(pParent
, mxMSF
);
365 else if( !mpDialog
->IsVisible() )
374 //-------------------------------------------------------------------------
375 void SAL_CALL
XMLFilterDialogComponent::initialize( const Sequence
< Any
>& aArguments
) throw(Exception
, RuntimeException
)
377 const Any
* pArguments
= aArguments
.getConstArray();
378 for(sal_Int32 i
=0; i
<aArguments
.getLength(); ++i
, ++pArguments
)
380 PropertyValue aProperty
;
381 if(*pArguments
>>= aProperty
)
383 if( aProperty
.Name
== "ParentWindow" )
385 aProperty
.Value
>>= mxParent
;
394 SAL_DLLPUBLIC_EXPORT
void * SAL_CALL
xsltdlg_component_getFactory(
395 const sal_Char
* pImplName
, void * pServiceManager
, void * /* pRegistryKey */ )
399 if( pServiceManager
)
401 Reference
< XSingleServiceFactory
> xFactory
;
403 OUString implName
= OUString::createFromAscii( pImplName
);
404 if ( implName
.equals(XMLFilterDialogComponent_getImplementationName()) )
406 xFactory
= createOneInstanceFactory(
407 reinterpret_cast< XMultiServiceFactory
* >( pServiceManager
),
408 OUString::createFromAscii( pImplName
),
409 XMLFilterDialogComponent_createInstance
, XMLFilterDialogComponent_getSupportedServiceNames() );
416 pRet
= xFactory
.get();
424 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */