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 <sal/config.h>
22 #include <boost/noncopyable.hpp>
23 #include "vcl/svapp.hxx"
24 #include "osl/mutex.hxx"
25 #include "cppuhelper/factory.hxx"
26 #include "cppuhelper/implementationentry.hxx"
27 #include "cppuhelper/implbase2.hxx"
28 #include <cppuhelper/supportsservice.hxx>
29 #include "com/sun/star/lang/XServiceInfo.hpp"
30 #include <com/sun/star/uno/XComponentContext.hpp>
31 #include "com/sun/star/awt/XRequestCallback.hpp"
33 /// anonymous implementation namespace
37 public ::cppu::WeakImplHelper2
<
38 css::lang::XServiceInfo
,
39 css::awt::XRequestCallback
>,
40 private boost::noncopyable
45 // ::com::sun::star::lang::XServiceInfo:
46 virtual OUString SAL_CALL
getImplementationName() throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
47 virtual sal_Bool SAL_CALL
supportsService(const OUString
& ServiceName
) throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
48 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
50 // ::com::sun::star::awt::XRequestCallback:
51 virtual void SAL_CALL
addCallback(const css::uno::Reference
< css::awt::XCallback
> & xCallback
, const ::com::sun::star::uno::Any
& aData
) throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
57 CallbackData( const css::uno::Reference
< css::awt::XCallback
>& rCallback
, const css::uno::Any
& rAny
) :
58 xCallback( rCallback
), aData( rAny
) {}
60 css::uno::Reference
< css::awt::XCallback
> xCallback
;
64 DECL_STATIC_LINK( AsyncCallback
, Notify_Impl
, CallbackData
* );
66 virtual ~AsyncCallback() {}
69 // com.sun.star.uno.XServiceInfo:
70 OUString SAL_CALL
AsyncCallback::getImplementationName() throw (css::uno::RuntimeException
, std::exception
)
72 return OUString("com.sun.star.awt.comp.AsyncCallback");
75 sal_Bool SAL_CALL
AsyncCallback::supportsService(OUString
const & serviceName
) throw (css::uno::RuntimeException
, std::exception
)
77 return cppu::supportsService(this, serviceName
);
80 css::uno::Sequence
< OUString
> SAL_CALL
AsyncCallback::getSupportedServiceNames() throw (css::uno::RuntimeException
, std::exception
)
82 css::uno::Sequence
< OUString
> s(1);
83 s
[0] = "com.sun.star.awt.AsyncCallback";
87 // ::com::sun::star::awt::XRequestCallback:
88 void SAL_CALL
AsyncCallback::addCallback(const css::uno::Reference
< css::awt::XCallback
> & xCallback
, const ::com::sun::star::uno::Any
& aData
) throw (css::uno::RuntimeException
, std::exception
)
90 if ( Application::IsInMain() )
92 SolarMutexGuard aSolarGuard
;
94 CallbackData
* pCallbackData
= new CallbackData( xCallback
, aData
);
95 Application::PostUserEvent( LINK( this, AsyncCallback
, Notify_Impl
), pCallbackData
);
99 // private asynchronous link to call reference to the callback object
100 IMPL_STATIC_LINK( AsyncCallback
, Notify_Impl
, CallbackData
*, pCallbackData
)
104 // Asynchronous execution
105 // Check pointer and reference before!
106 if ( pCallbackData
&& pCallbackData
->xCallback
.is() )
107 pCallbackData
->xCallback
->notify( pCallbackData
->aData
);
109 catch ( css::uno::Exception
& )
113 delete pCallbackData
;
117 } // closing anonymous implementation namespace
119 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
* SAL_CALL
120 com_sun_star_awt_comp_AsyncCallback_get_implementation(
121 css::uno::XComponentContext
*,
122 css::uno::Sequence
<css::uno::Any
> const &)
124 return cppu::acquire(new AsyncCallback());
127 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */