2010-10-14 08:27:31 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-06-21 14:30:25 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2007-11-27 10:43:50 +00:00
|
|
|
|
2014-04-09 14:14:26 +02:00
|
|
|
#include <sal/config.h>
|
2007-11-27 10:43:50 +00:00
|
|
|
|
2016-02-13 00:29:50 +11:00
|
|
|
#include <vcl/svapp.hxx>
|
2010-10-16 03:20:00 -05:00
|
|
|
#include "osl/mutex.hxx"
|
2007-11-27 10:43:50 +00:00
|
|
|
#include "cppuhelper/factory.hxx"
|
|
|
|
#include "cppuhelper/implementationentry.hxx"
|
2015-09-08 10:41:27 +09:00
|
|
|
#include <cppuhelper/implbase.hxx>
|
2013-10-21 19:04:05 -02:00
|
|
|
#include <cppuhelper/supportsservice.hxx>
|
2007-11-27 10:43:50 +00:00
|
|
|
#include "com/sun/star/lang/XServiceInfo.hpp"
|
2014-08-07 18:42:35 +02:00
|
|
|
#include <com/sun/star/uno/XComponentContext.hpp>
|
2007-11-27 10:43:50 +00:00
|
|
|
#include "com/sun/star/awt/XRequestCallback.hpp"
|
|
|
|
|
|
|
|
/// anonymous implementation namespace
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class AsyncCallback:
|
2015-09-08 10:41:27 +09:00
|
|
|
public ::cppu::WeakImplHelper<
|
2007-11-27 10:43:50 +00:00
|
|
|
css::lang::XServiceInfo,
|
2016-04-13 10:11:37 +02:00
|
|
|
css::awt::XRequestCallback>
|
2007-11-27 10:43:50 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-01-23 14:14:41 +01:00
|
|
|
AsyncCallback() {}
|
2016-04-13 10:11:37 +02:00
|
|
|
AsyncCallback(const AsyncCallback&) = delete;
|
|
|
|
AsyncCallback& operator=(const AsyncCallback&) = delete;
|
2007-11-27 10:43:50 +00:00
|
|
|
|
2015-11-09 09:05:08 +02:00
|
|
|
// css::lang::XServiceInfo:
|
2015-10-12 16:04:04 +02:00
|
|
|
virtual OUString SAL_CALL getImplementationName() throw (css::uno::RuntimeException, std::exception) override;
|
|
|
|
virtual sal_Bool SAL_CALL supportsService(const OUString & ServiceName) throw (css::uno::RuntimeException, std::exception) override;
|
|
|
|
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (css::uno::RuntimeException, std::exception) override;
|
2007-11-27 10:43:50 +00:00
|
|
|
|
2015-11-09 09:05:08 +02:00
|
|
|
// css::awt::XRequestCallback:
|
|
|
|
virtual void SAL_CALL addCallback(const css::uno::Reference< css::awt::XCallback > & xCallback, const css::uno::Any & aData) throw (css::uno::RuntimeException, std::exception) override;
|
2007-11-27 10:43:50 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
struct CallbackData
|
|
|
|
{
|
|
|
|
CallbackData( const css::uno::Reference< css::awt::XCallback >& rCallback, const css::uno::Any& rAny ) :
|
|
|
|
xCallback( rCallback ), aData( rAny ) {}
|
|
|
|
|
|
|
|
css::uno::Reference< css::awt::XCallback > xCallback;
|
|
|
|
css::uno::Any aData;
|
|
|
|
};
|
|
|
|
|
2015-08-27 13:08:02 +02:00
|
|
|
DECL_STATIC_LINK_TYPED( AsyncCallback, Notify_Impl, void*, void );
|
2007-11-27 10:43:50 +00:00
|
|
|
|
|
|
|
virtual ~AsyncCallback() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
// com.sun.star.uno.XServiceInfo:
|
2014-02-25 21:31:58 +01:00
|
|
|
OUString SAL_CALL AsyncCallback::getImplementationName() throw (css::uno::RuntimeException, std::exception)
|
2007-11-27 10:43:50 +00:00
|
|
|
{
|
2014-01-23 14:14:41 +01:00
|
|
|
return OUString("com.sun.star.awt.comp.AsyncCallback");
|
2007-11-27 10:43:50 +00:00
|
|
|
}
|
|
|
|
|
2014-04-03 13:52:06 +02:00
|
|
|
sal_Bool SAL_CALL AsyncCallback::supportsService(OUString const & serviceName) throw (css::uno::RuntimeException, std::exception)
|
2007-11-27 10:43:50 +00:00
|
|
|
{
|
2013-10-21 19:04:05 -02:00
|
|
|
return cppu::supportsService(this, serviceName);
|
2007-11-27 10:43:50 +00:00
|
|
|
}
|
|
|
|
|
2014-02-25 21:31:58 +01:00
|
|
|
css::uno::Sequence< OUString > SAL_CALL AsyncCallback::getSupportedServiceNames() throw (css::uno::RuntimeException, std::exception)
|
2007-11-27 10:43:50 +00:00
|
|
|
{
|
2015-11-15 08:43:35 +02:00
|
|
|
css::uno::Sequence< OUString > s { "com.sun.star.awt.AsyncCallback" };
|
2014-01-23 14:14:41 +01:00
|
|
|
return s;
|
2007-11-27 10:43:50 +00:00
|
|
|
}
|
|
|
|
|
2015-11-09 09:05:08 +02:00
|
|
|
// css::awt::XRequestCallback:
|
|
|
|
void SAL_CALL AsyncCallback::addCallback(const css::uno::Reference< css::awt::XCallback > & xCallback, const css::uno::Any & aData) throw (css::uno::RuntimeException, std::exception)
|
2007-11-27 10:43:50 +00:00
|
|
|
{
|
|
|
|
if ( Application::IsInMain() )
|
|
|
|
{
|
2010-10-16 03:20:00 -05:00
|
|
|
SolarMutexGuard aSolarGuard;
|
|
|
|
|
2007-11-27 10:43:50 +00:00
|
|
|
CallbackData* pCallbackData = new CallbackData( xCallback, aData );
|
2015-04-28 15:10:58 +02:00
|
|
|
Application::PostUserEvent( LINK( this, AsyncCallback, Notify_Impl ), pCallbackData );
|
2007-11-27 10:43:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// private asynchronous link to call reference to the callback object
|
2015-08-27 13:08:02 +02:00
|
|
|
IMPL_STATIC_LINK_TYPED( AsyncCallback, Notify_Impl, void*, p, void )
|
2007-11-27 10:43:50 +00:00
|
|
|
{
|
2015-08-27 13:08:02 +02:00
|
|
|
CallbackData* pCallbackData = static_cast<CallbackData*>(p);
|
2007-11-27 10:43:50 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
// Asynchronous execution
|
|
|
|
// Check pointer and reference before!
|
|
|
|
if ( pCallbackData && pCallbackData->xCallback.is() )
|
|
|
|
pCallbackData->xCallback->notify( pCallbackData->aData );
|
|
|
|
}
|
|
|
|
catch ( css::uno::Exception& )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
delete pCallbackData;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // closing anonymous implementation namespace
|
|
|
|
|
2014-01-23 14:14:41 +01:00
|
|
|
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
|
|
|
|
com_sun_star_awt_comp_AsyncCallback_get_implementation(
|
|
|
|
css::uno::XComponentContext *,
|
|
|
|
css::uno::Sequence<css::uno::Any> const &)
|
2007-11-27 10:43:50 +00:00
|
|
|
{
|
2014-01-23 14:14:41 +01:00
|
|
|
return cppu::acquire(new AsyncCallback());
|
2007-11-27 10:43:50 +00:00
|
|
|
}
|
|
|
|
|
2011-05-16 23:44:29 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|