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