Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <osl/mutex.hxx>
30 : : #include <toolkit/awt/vclxwindow.hxx>
31 : :
32 : : #include <osl/thread.h>
33 : : #include <cppuhelper/factory.hxx>
34 : : #include <cppuhelper/typeprovider.hxx>
35 : : #include <cppuhelper/component.hxx>
36 : : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
37 : : #include <com/sun/star/frame/XDesktop.hpp>
38 : : #include <com/sun/star/frame/XTerminateListener.hpp>
39 : : #include <cppuhelper/implbase4.hxx>
40 : : #include <com/sun/star/lang/XServiceInfo.hpp>
41 : : #include <com/sun/star/lang/XInitialization.hpp>
42 : : #include <com/sun/star/awt/XWindow.hpp>
43 : : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
44 : : #include <com/sun/star/beans/PropertyValue.hpp>
45 : : #include <tools/resmgr.hxx>
46 : : #include <vcl/svapp.hxx>
47 : : #include <rtl/instance.hxx>
48 : :
49 : : #include <svl/solar.hrc>
50 : :
51 : : #include "xmlfiltersettingsdialog.hxx"
52 : :
53 : : using namespace ::rtl;
54 : : using namespace ::cppu;
55 : : using namespace ::osl;
56 : : using namespace ::com::sun::star::uno;
57 : : using namespace ::com::sun::star::lang;
58 : : using namespace ::com::sun::star::beans;
59 : : using namespace ::com::sun::star::registry;
60 : : using namespace ::com::sun::star::frame;
61 : :
62 : :
63 : 0 : class XMLFilterDialogComponentBase
64 : : {
65 : : protected:
66 : : ::osl::Mutex maMutex;
67 : : };
68 : :
69 : :
70 : : class XMLFilterDialogComponent : public XMLFilterDialogComponentBase,
71 : : public OComponentHelper,
72 : : public ::com::sun::star::ui::dialogs::XExecutableDialog,
73 : : public XServiceInfo,
74 : : public XInitialization,
75 : : public XTerminateListener
76 : : {
77 : : public:
78 : : XMLFilterDialogComponent( const Reference< XMultiServiceFactory >& rxMSF );
79 : : virtual ~XMLFilterDialogComponent();
80 : :
81 : : protected:
82 : : // XInterface
83 : : virtual Any SAL_CALL queryInterface( const Type& aType ) throw (RuntimeException);
84 : : virtual Any SAL_CALL queryAggregation( Type const & rType ) throw (RuntimeException);
85 : : virtual void SAL_CALL acquire() throw ();
86 : : virtual void SAL_CALL release() throw ();
87 : :
88 : : // XTypeProvider
89 : : virtual Sequence< sal_Int8 > SAL_CALL getImplementationId() throw(RuntimeException);
90 : : virtual Sequence< Type > SAL_CALL getTypes() throw (RuntimeException);
91 : :
92 : : // XServiceInfo
93 : : virtual ::rtl::OUString SAL_CALL getImplementationName() throw(com::sun::star::uno::RuntimeException);
94 : : virtual sal_Bool SAL_CALL supportsService(const ::rtl::OUString& ServiceName) throw(RuntimeException);
95 : : virtual Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (RuntimeException);
96 : :
97 : : // XExecutableDialog
98 : : virtual void SAL_CALL setTitle( const ::rtl::OUString& aTitle ) throw(RuntimeException);
99 : : virtual sal_Int16 SAL_CALL execute( ) throw(RuntimeException);
100 : :
101 : : // XInitialization
102 : : virtual void SAL_CALL initialize( const Sequence< Any >& aArguments ) throw(Exception, RuntimeException);
103 : :
104 : : // XTerminateListener
105 : : virtual void SAL_CALL queryTermination( const EventObject& Event ) throw (TerminationVetoException, RuntimeException);
106 : : virtual void SAL_CALL notifyTermination( const EventObject& Event ) throw (RuntimeException);
107 : : virtual void SAL_CALL disposing( const EventObject& Source ) throw (RuntimeException);
108 : :
109 : : /** Called in dispose method after the listeners were notified.
110 : : */
111 : : virtual void SAL_CALL disposing();
112 : :
113 : : private:
114 : : com::sun::star::uno::Reference<com::sun::star::awt::XWindow> mxParent; /// parent window
115 : : com::sun::star::uno::Reference< XMultiServiceFactory > mxMSF;
116 : :
117 : : static ResMgr* mpResMgr;
118 : : XMLFilterSettingsDialog* mpDialog;
119 : : };
120 : :
121 : : //-------------------------------------------------------------------------
122 : :
123 : : ResMgr* XMLFilterDialogComponent::mpResMgr = NULL;
124 : :
125 : 0 : XMLFilterDialogComponent::XMLFilterDialogComponent( const com::sun::star::uno::Reference< XMultiServiceFactory >& rxMSF ) :
126 : : OComponentHelper( maMutex ),
127 : : mxMSF( rxMSF ),
128 : 0 : mpDialog( NULL )
129 : : {
130 : 0 : Reference< XDesktop > xDesktop( mxMSF->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.Desktop" )) ), UNO_QUERY );
131 : 0 : if( xDesktop.is() )
132 : : {
133 : 0 : Reference< XTerminateListener > xListener( this );
134 : 0 : xDesktop->addTerminateListener( xListener );
135 : 0 : }
136 : 0 : }
137 : :
138 : : //-------------------------------------------------------------------------
139 : :
140 : 0 : XMLFilterDialogComponent::~XMLFilterDialogComponent()
141 : : {
142 : 0 : }
143 : :
144 : : //-------------------------------------------------------------------------
145 : :
146 : : // XInterface
147 : 0 : Any SAL_CALL XMLFilterDialogComponent::queryInterface( const Type& aType ) throw (RuntimeException)
148 : : {
149 : 0 : return OComponentHelper::queryInterface( aType );
150 : : }
151 : :
152 : : //-------------------------------------------------------------------------
153 : :
154 : 0 : Any SAL_CALL XMLFilterDialogComponent::queryAggregation( Type const & rType ) throw (RuntimeException)
155 : : {
156 : 0 : if (rType == ::getCppuType( (Reference< ::com::sun::star::ui::dialogs::XExecutableDialog > const *)0 ))
157 : : {
158 : 0 : void * p = static_cast< ::com::sun::star::ui::dialogs::XExecutableDialog * >( this );
159 : 0 : return Any( &p, rType );
160 : : }
161 : 0 : else if (rType == ::getCppuType( (Reference< XServiceInfo > const *)0 ))
162 : : {
163 : 0 : void * p = static_cast< XServiceInfo * >( this );
164 : 0 : return Any( &p, rType );
165 : : }
166 : 0 : else if (rType == ::getCppuType( (Reference< XInitialization > const *)0 ))
167 : : {
168 : 0 : void * p = static_cast< XInitialization * >( this );
169 : 0 : return Any( &p, rType );
170 : : }
171 : 0 : else if (rType == ::getCppuType( (Reference< XTerminateListener > const *)0 ))
172 : : {
173 : 0 : void * p = static_cast< XTerminateListener * >( this );
174 : 0 : return Any( &p, rType );
175 : : }
176 : 0 : return OComponentHelper::queryAggregation( rType );
177 : : }
178 : :
179 : : //-------------------------------------------------------------------------
180 : :
181 : 0 : void SAL_CALL XMLFilterDialogComponent::acquire() throw ()
182 : : {
183 : 0 : OComponentHelper::acquire();
184 : 0 : }
185 : :
186 : : //-------------------------------------------------------------------------
187 : :
188 : 0 : void SAL_CALL XMLFilterDialogComponent::release() throw ()
189 : : {
190 : 0 : OComponentHelper::release();
191 : 0 : }
192 : :
193 : : //-------------------------------------------------------------------------
194 : :
195 : 0 : OUString XMLFilterDialogComponent_getImplementationName() throw ( RuntimeException )
196 : : {
197 : 0 : return OUString( RTL_CONSTASCII_USTRINGPARAM( "XMLFilterDialogComponent" ) );
198 : : }
199 : :
200 : : //-------------------------------------------------------------------------
201 : :
202 : 0 : Sequence< OUString > SAL_CALL XMLFilterDialogComponent_getSupportedServiceNames() throw ( RuntimeException )
203 : : {
204 : 0 : OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.ui.XSLTFilterDialog" ) );
205 : 0 : Sequence< ::rtl::OUString > aSupported( &aServiceName, 1 );
206 : 0 : return aSupported;
207 : : }
208 : :
209 : : //-------------------------------------------------------------------------
210 : :
211 : 0 : sal_Bool SAL_CALL XMLFilterDialogComponent_supportsService( const OUString& ServiceName ) throw ( RuntimeException )
212 : : {
213 : 0 : Sequence< ::rtl::OUString > aSupported(XMLFilterDialogComponent_getSupportedServiceNames());
214 : 0 : const ::rtl::OUString* pArray = aSupported.getConstArray();
215 : 0 : for (sal_Int32 i = 0; i < aSupported.getLength(); ++i, ++pArray)
216 : 0 : if (pArray->equals(ServiceName))
217 : 0 : return sal_True;
218 : 0 : return sal_False;
219 : : }
220 : :
221 : : //-------------------------------------------------------------------------
222 : :
223 : 0 : Reference< XInterface > SAL_CALL XMLFilterDialogComponent_createInstance( const Reference< XMultiServiceFactory > & rSMgr) throw ( Exception )
224 : : {
225 : 0 : return (OWeakObject*)new XMLFilterDialogComponent( rSMgr );
226 : : }
227 : :
228 : : //-------------------------------------------------------------------------
229 : 0 : ::rtl::OUString SAL_CALL XMLFilterDialogComponent::getImplementationName() throw(com::sun::star::uno::RuntimeException)
230 : : {
231 : 0 : return XMLFilterDialogComponent_getImplementationName();
232 : : }
233 : :
234 : : //-------------------------------------------------------------------------
235 : :
236 : : namespace { struct lcl_ImplId : public rtl::Static< ::cppu::OImplementationId, lcl_ImplId > {}; }
237 : :
238 : 0 : Sequence< sal_Int8 > SAL_CALL XMLFilterDialogComponent::getImplementationId( void ) throw( RuntimeException )
239 : : {
240 : 0 : ::cppu::OImplementationId &rID = lcl_ImplId::get();
241 : 0 : return rID.getImplementationId();
242 : : }
243 : :
244 : : //-------------------------------------------------------------------------
245 : :
246 : : namespace
247 : : {
248 : 0 : class DialogComponentTypes
249 : : {
250 : : private:
251 : : OTypeCollection m_aTypes;
252 : : public:
253 : 0 : DialogComponentTypes() :
254 : : m_aTypes(
255 : 0 : ::getCppuType( (const Reference< XComponent > *)0 ),
256 : 0 : ::getCppuType( (const Reference< XTypeProvider > *)0 ),
257 : 0 : ::getCppuType( (const Reference< XAggregation > *)0 ),
258 : 0 : ::getCppuType( (const Reference< XWeak > *)0 ),
259 : 0 : ::getCppuType( (const Reference< XServiceInfo > *)0 ),
260 : 0 : ::getCppuType( (const Reference< XInitialization > *)0 ),
261 : 0 : ::getCppuType( (const Reference< XTerminateListener > *)0 ),
262 : 0 : ::getCppuType( (const Reference< ::com::sun::star::ui::dialogs::XExecutableDialog > *)0 ))
263 : : {
264 : 0 : }
265 : 0 : OTypeCollection& getTypeCollection() { return m_aTypes; }
266 : : };
267 : :
268 : : struct theDialogComponentTypes : rtl::Static<DialogComponentTypes, theDialogComponentTypes> {};
269 : : }
270 : :
271 : 0 : Sequence< Type > XMLFilterDialogComponent::getTypes() throw (RuntimeException)
272 : : {
273 : 0 : return theDialogComponentTypes::get().getTypeCollection().getTypes();
274 : : }
275 : :
276 : : //-------------------------------------------------------------------------
277 : :
278 : 0 : Sequence< ::rtl::OUString > SAL_CALL XMLFilterDialogComponent::getSupportedServiceNames() throw(com::sun::star::uno::RuntimeException)
279 : : {
280 : 0 : return XMLFilterDialogComponent_getSupportedServiceNames();
281 : : }
282 : :
283 : : //-------------------------------------------------------------------------
284 : 0 : sal_Bool SAL_CALL XMLFilterDialogComponent::supportsService(const ::rtl::OUString& ServiceName) throw(RuntimeException)
285 : : {
286 : 0 : return XMLFilterDialogComponent_supportsService( ServiceName );
287 : : }
288 : :
289 : : //-------------------------------------------------------------------------
290 : :
291 : : /** Called in dispose method after the listeners were notified.
292 : : */
293 : 0 : void SAL_CALL XMLFilterDialogComponent::disposing()
294 : : {
295 : 0 : ::SolarMutexGuard aGuard;
296 : :
297 : 0 : if( mpDialog )
298 : : {
299 : 0 : delete mpDialog;
300 : 0 : mpDialog = NULL;
301 : : }
302 : :
303 : 0 : if( mpResMgr )
304 : : {
305 : 0 : delete mpResMgr;
306 : 0 : mpResMgr = NULL;
307 : 0 : }
308 : 0 : }
309 : :
310 : : //-------------------------------------------------------------------------
311 : :
312 : : // XTerminateListener
313 : 0 : void SAL_CALL XMLFilterDialogComponent::queryTermination( const EventObject& /* Event */ ) throw (TerminationVetoException, RuntimeException)
314 : : {
315 : 0 : ::SolarMutexGuard aGuard;
316 : :
317 : : // we will never give a veto here
318 : 0 : if( mpDialog && !mpDialog->isClosable() )
319 : : {
320 : 0 : mpDialog->ToTop();
321 : 0 : throw TerminationVetoException();
322 : 0 : }
323 : 0 : }
324 : :
325 : : //-------------------------------------------------------------------------
326 : :
327 : 0 : void SAL_CALL XMLFilterDialogComponent::notifyTermination( const EventObject& /* Event */ ) throw (RuntimeException)
328 : : {
329 : : // we are going down, so dispose us!
330 : 0 : dispose();
331 : 0 : }
332 : :
333 : 0 : void SAL_CALL XMLFilterDialogComponent::disposing( const EventObject& /* Source */ ) throw (RuntimeException)
334 : : {
335 : 0 : }
336 : :
337 : : //-------------------------------------------------------------------------
338 : 0 : void SAL_CALL XMLFilterDialogComponent::setTitle( const ::rtl::OUString& /* _rTitle */ ) throw(RuntimeException)
339 : : {
340 : 0 : }
341 : :
342 : : //-------------------------------------------------------------------------
343 : 0 : sal_Int16 SAL_CALL XMLFilterDialogComponent::execute( ) throw(RuntimeException)
344 : : {
345 : 0 : ::SolarMutexGuard aGuard;
346 : :
347 : 0 : if( NULL == mpResMgr )
348 : : {
349 : 0 : mpResMgr = ResMgr::CreateResMgr( "xsltdlg", Application::GetSettings().GetUILocale() );
350 : : }
351 : :
352 : 0 : if( NULL == mpDialog )
353 : : {
354 : 0 : Window* pParent = NULL;
355 : 0 : if( mxParent.is() )
356 : : {
357 : 0 : VCLXWindow* pImplementation = VCLXWindow::GetImplementation(mxParent);
358 : 0 : if (pImplementation)
359 : 0 : pParent = pImplementation->GetWindow();
360 : : }
361 : :
362 : 0 : Reference< XComponent > xComp( this );
363 : 0 : mpDialog = new XMLFilterSettingsDialog( pParent, *mpResMgr, mxMSF );
364 : 0 : mpDialog->ShowWindow();
365 : : }
366 : 0 : else if( !mpDialog->IsVisible() )
367 : : {
368 : 0 : mpDialog->ShowWindow();
369 : : }
370 : 0 : mpDialog->ToTop();
371 : :
372 : 0 : return 0;
373 : : }
374 : :
375 : : //-------------------------------------------------------------------------
376 : 0 : void SAL_CALL XMLFilterDialogComponent::initialize( const Sequence< Any >& aArguments ) throw(Exception, RuntimeException)
377 : : {
378 : 0 : const Any* pArguments = aArguments.getConstArray();
379 : 0 : for(sal_Int32 i=0; i<aArguments.getLength(); ++i, ++pArguments)
380 : : {
381 : 0 : PropertyValue aProperty;
382 : 0 : if(*pArguments >>= aProperty)
383 : : {
384 : 0 : if( aProperty.Name.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "ParentWindow" ) ) == 0 )
385 : : {
386 : 0 : aProperty.Value >>= mxParent;
387 : : }
388 : : }
389 : 0 : }
390 : 0 : }
391 : :
392 : :
393 : : extern "C"
394 : : {
395 : 0 : SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(
396 : : const sal_Char * pImplName, void * pServiceManager, void * /* pRegistryKey */ )
397 : : {
398 : 0 : void * pRet = 0;
399 : :
400 : 0 : if( pServiceManager )
401 : : {
402 : 0 : Reference< XSingleServiceFactory > xFactory;
403 : :
404 : 0 : OUString implName = OUString::createFromAscii( pImplName );
405 : 0 : if ( implName.equals(XMLFilterDialogComponent_getImplementationName()) )
406 : : {
407 : : xFactory = createOneInstanceFactory(
408 : : reinterpret_cast< XMultiServiceFactory * >( pServiceManager ),
409 : : OUString::createFromAscii( pImplName ),
410 : 0 : XMLFilterDialogComponent_createInstance, XMLFilterDialogComponent_getSupportedServiceNames() );
411 : :
412 : : }
413 : :
414 : 0 : if (xFactory.is())
415 : : {
416 : 0 : xFactory->acquire();
417 : 0 : pRet = xFactory.get();
418 : 0 : }
419 : : }
420 : :
421 : 0 : return pRet;
422 : : }
423 : : }
424 : :
425 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|