1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlfilterdialogcomponent.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_filter.hxx"
33 #include <osl/mutex.hxx>
34 #include <vos/mutex.hxx>
35 #include <toolkit/awt/vclxwindow.hxx>
37 #include <osl/thread.h>
38 #include <cppuhelper/factory.hxx>
39 #include <cppuhelper/typeprovider.hxx>
40 #include <cppuhelper/component.hxx>
41 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
42 #include <com/sun/star/frame/XDesktop.hpp>
43 #include <com/sun/star/frame/XTerminateListener.hpp>
44 #include <cppuhelper/implbase4.hxx>
45 #include <com/sun/star/lang/XServiceInfo.hpp>
46 #include <com/sun/star/lang/XInitialization.hpp>
47 #include <com/sun/star/awt/XWindow.hpp>
48 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
49 #include <com/sun/star/beans/PropertyValue.hpp>
50 #include <toolkit/awt/vclxwindow.hxx>
51 #include <tools/resmgr.hxx>
52 #include <vcl/svapp.hxx>
54 #include <svtools/solar.hrc>
56 #include "xmlfiltersettingsdialog.hxx"
58 //using namespace ::comphelper;
59 using namespace ::rtl
;
60 using namespace ::cppu
;
61 using namespace ::osl
;
62 using namespace ::com::sun::star::uno
;
63 using namespace ::com::sun::star::lang
;
64 using namespace ::com::sun::star::beans
;
65 using namespace ::com::sun::star::registry
;
66 using namespace ::com::sun::star::frame
;
69 class XMLFilterDialogComponentBase
76 class XMLFilterDialogComponent
: public XMLFilterDialogComponentBase
,
77 public OComponentHelper
,
78 public ::com::sun::star::ui::dialogs::XExecutableDialog
,
80 public XInitialization
,
81 public XTerminateListener
84 XMLFilterDialogComponent( const Reference
< XMultiServiceFactory
>& rxMSF
);
85 virtual ~XMLFilterDialogComponent();
89 virtual Any SAL_CALL
queryInterface( const Type
& aType
) throw (RuntimeException
);
90 virtual Any SAL_CALL
queryAggregation( Type
const & rType
) throw (RuntimeException
);
91 virtual void SAL_CALL
acquire() throw ();
92 virtual void SAL_CALL
release() throw ();
95 virtual Sequence
< sal_Int8
> SAL_CALL
getImplementationId() throw(RuntimeException
);
96 virtual Sequence
< Type
> SAL_CALL
getTypes() throw (RuntimeException
);
99 virtual ::rtl::OUString SAL_CALL
getImplementationName() throw(com::sun::star::uno::RuntimeException
);
100 virtual sal_Bool SAL_CALL
supportsService(const ::rtl::OUString
& ServiceName
) throw(RuntimeException
);
101 virtual Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedServiceNames( ) throw (RuntimeException
);
104 virtual void SAL_CALL
setTitle( const ::rtl::OUString
& aTitle
) throw(RuntimeException
);
105 virtual sal_Int16 SAL_CALL
execute( ) throw(RuntimeException
);
108 virtual void SAL_CALL
initialize( const Sequence
< Any
>& aArguments
) throw(Exception
, RuntimeException
);
110 // XTerminateListener
111 virtual void SAL_CALL
queryTermination( const EventObject
& Event
) throw (TerminationVetoException
, RuntimeException
);
112 virtual void SAL_CALL
notifyTermination( const EventObject
& Event
) throw (RuntimeException
);
113 virtual void SAL_CALL
disposing( const EventObject
& Source
) throw (RuntimeException
);
115 /** Called in dispose method after the listeners were notified.
117 virtual void SAL_CALL
disposing();
120 com::sun::star::uno::Reference
<com::sun::star::awt::XWindow
> mxParent
; /// parent window
121 com::sun::star::uno::Reference
< XMultiServiceFactory
> mxMSF
;
123 static ResMgr
* mpResMgr
;
124 XMLFilterSettingsDialog
* mpDialog
;
127 //-------------------------------------------------------------------------
129 ResMgr
* XMLFilterDialogComponent::mpResMgr
= NULL
;
131 XMLFilterDialogComponent::XMLFilterDialogComponent( const com::sun::star::uno::Reference
< XMultiServiceFactory
>& rxMSF
) :
132 OComponentHelper( maMutex
),
136 Reference
< XDesktop
> xDesktop( mxMSF
->createInstance( OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ), UNO_QUERY
);
139 Reference
< XTerminateListener
> xListener( this );
140 xDesktop
->addTerminateListener( xListener
);
144 //-------------------------------------------------------------------------
146 XMLFilterDialogComponent::~XMLFilterDialogComponent()
150 //-------------------------------------------------------------------------
153 Any SAL_CALL
XMLFilterDialogComponent::queryInterface( const Type
& aType
) throw (RuntimeException
)
155 return OComponentHelper::queryInterface( aType
);
158 //-------------------------------------------------------------------------
160 Any SAL_CALL
XMLFilterDialogComponent::queryAggregation( Type
const & rType
) throw (RuntimeException
)
162 if (rType
== ::getCppuType( (Reference
< ::com::sun::star::ui::dialogs::XExecutableDialog
> const *)0 ))
164 void * p
= static_cast< ::com::sun::star::ui::dialogs::XExecutableDialog
* >( this );
165 return Any( &p
, rType
);
167 else if (rType
== ::getCppuType( (Reference
< XServiceInfo
> const *)0 ))
169 void * p
= static_cast< XServiceInfo
* >( this );
170 return Any( &p
, rType
);
172 else if (rType
== ::getCppuType( (Reference
< XInitialization
> const *)0 ))
174 void * p
= static_cast< XInitialization
* >( this );
175 return Any( &p
, rType
);
177 else if (rType
== ::getCppuType( (Reference
< XTerminateListener
> const *)0 ))
179 void * p
= static_cast< XTerminateListener
* >( this );
180 return Any( &p
, rType
);
182 return OComponentHelper::queryAggregation( rType
);
185 //-------------------------------------------------------------------------
187 void SAL_CALL
XMLFilterDialogComponent::acquire() throw ()
189 OComponentHelper::acquire();
192 //-------------------------------------------------------------------------
194 void SAL_CALL
XMLFilterDialogComponent::release() throw ()
196 OComponentHelper::release();
199 //-------------------------------------------------------------------------
201 OUString
XMLFilterDialogComponent_getImplementationName() throw ( RuntimeException
)
203 return OUString( RTL_CONSTASCII_USTRINGPARAM( "XMLFilterDialogComponent" ) );
206 //-------------------------------------------------------------------------
208 Sequence
< OUString
> SAL_CALL
XMLFilterDialogComponent_getSupportedServiceNames() throw ( RuntimeException
)
210 OUString
aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.ui.XSLTFilterDialog" ) );
211 Sequence
< ::rtl::OUString
> aSupported( &aServiceName
, 1 );
215 //-------------------------------------------------------------------------
217 sal_Bool SAL_CALL
XMLFilterDialogComponent_supportsService( const OUString
& ServiceName
) throw ( RuntimeException
)
219 Sequence
< ::rtl::OUString
> aSupported(XMLFilterDialogComponent_getSupportedServiceNames());
220 const ::rtl::OUString
* pArray
= aSupported
.getConstArray();
221 for (sal_Int32 i
= 0; i
< aSupported
.getLength(); ++i
, ++pArray
)
222 if (pArray
->equals(ServiceName
))
227 //-------------------------------------------------------------------------
229 Reference
< XInterface
> SAL_CALL
XMLFilterDialogComponent_createInstance( const Reference
< XMultiServiceFactory
> & rSMgr
) throw ( Exception
)
231 return (OWeakObject
*)new XMLFilterDialogComponent( rSMgr
);
234 //-------------------------------------------------------------------------
235 ::rtl::OUString SAL_CALL
XMLFilterDialogComponent::getImplementationName() throw(com::sun::star::uno::RuntimeException
)
237 return XMLFilterDialogComponent_getImplementationName();
240 //-------------------------------------------------------------------------
242 Sequence
< sal_Int8
> SAL_CALL
XMLFilterDialogComponent::getImplementationId( void ) throw( RuntimeException
)
244 static OImplementationId
* pId
= 0;
247 MutexGuard
aGuard( Mutex::getGlobalMutex() );
250 static OImplementationId aId
;
254 return pId
->getImplementationId();
257 //-------------------------------------------------------------------------
259 Sequence
< Type
> XMLFilterDialogComponent::getTypes() throw (RuntimeException
)
261 static OTypeCollection
* s_pTypes
= 0;
264 MutexGuard
aGuard( Mutex::getGlobalMutex() );
267 static OTypeCollection
s_aTypes(
268 ::getCppuType( (const Reference
< XComponent
> *)0 ),
269 ::getCppuType( (const Reference
< XTypeProvider
> *)0 ),
270 ::getCppuType( (const Reference
< XAggregation
> *)0 ),
271 ::getCppuType( (const Reference
< XWeak
> *)0 ),
272 ::getCppuType( (const Reference
< XServiceInfo
> *)0 ),
273 ::getCppuType( (const Reference
< XInitialization
> *)0 ),
274 ::getCppuType( (const Reference
< XTerminateListener
> *)0 ),
275 ::getCppuType( (const Reference
< ::com::sun::star::ui::dialogs::XExecutableDialog
> *)0 ));
276 s_pTypes
= &s_aTypes
;
279 return s_pTypes
->getTypes();
282 //-------------------------------------------------------------------------
284 Sequence
< ::rtl::OUString
> SAL_CALL
XMLFilterDialogComponent::getSupportedServiceNames() throw(com::sun::star::uno::RuntimeException
)
286 return XMLFilterDialogComponent_getSupportedServiceNames();
289 //-------------------------------------------------------------------------
290 sal_Bool SAL_CALL
XMLFilterDialogComponent::supportsService(const ::rtl::OUString
& ServiceName
) throw(RuntimeException
)
292 return XMLFilterDialogComponent_supportsService( ServiceName
);
295 //-------------------------------------------------------------------------
297 /** Called in dispose method after the listeners were notified.
299 void SAL_CALL
XMLFilterDialogComponent::disposing()
301 vos::OGuard
aGuard( Application::GetSolarMutex() );
316 //-------------------------------------------------------------------------
318 // XTerminateListener
319 void SAL_CALL
XMLFilterDialogComponent::queryTermination( const EventObject
& /* Event */ ) throw (TerminationVetoException
, RuntimeException
)
321 vos::OGuard
aGuard( Application::GetSolarMutex() );
323 // we will never give a veto here
324 if( mpDialog
&& !mpDialog
->isClosable() )
327 throw TerminationVetoException();
331 //-------------------------------------------------------------------------
333 void SAL_CALL
XMLFilterDialogComponent::notifyTermination( const EventObject
& /* Event */ ) throw (RuntimeException
)
335 // we are going down, so dispose us!
339 void SAL_CALL
XMLFilterDialogComponent::disposing( const EventObject
& /* Source */ ) throw (RuntimeException
)
343 //-------------------------------------------------------------------------
344 void SAL_CALL
XMLFilterDialogComponent::setTitle( const ::rtl::OUString
& /* _rTitle */ ) throw(RuntimeException
)
348 //-------------------------------------------------------------------------
349 sal_Int16 SAL_CALL
XMLFilterDialogComponent::execute( ) throw(RuntimeException
)
351 vos::OGuard
aGuard( Application::GetSolarMutex() );
353 if( NULL
== mpResMgr
)
355 ByteString
aResMgrName( "xsltdlg" );
357 mpResMgr
= ResMgr::CreateResMgr( aResMgrName
.GetBuffer(), Application::GetSettings().GetUILocale() );
360 if( NULL
== mpDialog
)
362 Window
* pParent
= NULL
;
365 VCLXWindow
* pImplementation
= VCLXWindow::GetImplementation(mxParent
);
367 pParent
= pImplementation
->GetWindow();
370 Reference
< XComponent
> xComp( this );
371 mpDialog
= new XMLFilterSettingsDialog( pParent
, *mpResMgr
, mxMSF
);
372 mpDialog
->ShowWindow();
374 else if( !mpDialog
->IsVisible() )
376 mpDialog
->ShowWindow();
383 //-------------------------------------------------------------------------
384 void SAL_CALL
XMLFilterDialogComponent::initialize( const Sequence
< Any
>& aArguments
) throw(Exception
, RuntimeException
)
386 const Any
* pArguments
= aArguments
.getConstArray();
387 for(sal_Int32 i
=0; i
<aArguments
.getLength(); ++i
, ++pArguments
)
389 PropertyValue aProperty
;
390 if(*pArguments
>>= aProperty
)
392 if( aProperty
.Name
.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "ParentWindow" ) ) == 0 )
394 aProperty
.Value
>>= mxParent
;
403 //==================================================================================================
404 void SAL_CALL
component_getImplementationEnvironment(
405 const sal_Char
** ppEnvTypeName
, uno_Environment
** /* ppEnv */ )
407 *ppEnvTypeName
= CPPU_CURRENT_LANGUAGE_BINDING_NAME
;
409 //==================================================================================================
411 void singlecomponent_writeInfo( Reference
< XRegistryKey
>& xNewKey
, const Sequence
< OUString
> & rSNL
)
413 const OUString
* pArray
= rSNL
.getConstArray();
414 for ( sal_Int32 nPos
= rSNL
.getLength(); nPos
--; )
415 xNewKey
->createKey( pArray
[nPos
] );
418 sal_Bool SAL_CALL
component_writeInfo(
419 void * /* pServiceManager */, void * pRegistryKey
)
425 Reference
< XRegistryKey
> xNewKey(
426 reinterpret_cast< XRegistryKey
* >( pRegistryKey
)->createKey( XMLFilterDialogComponent_getImplementationName() ) );
427 xNewKey
= xNewKey
->createKey( OUString::createFromAscii( "/UNO/SERVICES" ) );
429 singlecomponent_writeInfo( xNewKey
, XMLFilterDialogComponent_getSupportedServiceNames() );
433 catch (InvalidRegistryException
&)
435 OSL_ENSURE( sal_False
, "### InvalidRegistryException!" );
440 //==================================================================================================
441 void * SAL_CALL
component_getFactory(
442 const sal_Char
* pImplName
, void * pServiceManager
, void * /* pRegistryKey */ )
446 if( pServiceManager
)
448 Reference
< XSingleServiceFactory
> xFactory
;
450 OUString implName
= OUString::createFromAscii( pImplName
);
451 if ( implName
.equals(XMLFilterDialogComponent_getImplementationName()) )
453 xFactory
= createOneInstanceFactory(
454 reinterpret_cast< XMultiServiceFactory
* >( pServiceManager
),
455 OUString::createFromAscii( pImplName
),
456 XMLFilterDialogComponent_createInstance
, XMLFilterDialogComponent_getSupportedServiceNames() );
463 pRet
= xFactory
.get();