bump product version to 6.3.0.0.beta1
[LibreOffice.git] / toolkit / source / awt / asynccallback.cxx
blobc37b20930a71ef3d9842dc45f4b7e8464d83d812
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <vcl/svapp.hxx>
23 #include <cppuhelper/factory.hxx>
24 #include <cppuhelper/implementationentry.hxx>
25 #include <cppuhelper/implbase.hxx>
26 #include <cppuhelper/supportsservice.hxx>
27 #include <com/sun/star/lang/XServiceInfo.hpp>
28 #include <com/sun/star/uno/XComponentContext.hpp>
29 #include <com/sun/star/awt/XRequestCallback.hpp>
31 /// anonymous implementation namespace
32 namespace {
34 class AsyncCallback:
35 public ::cppu::WeakImplHelper<
36 css::lang::XServiceInfo,
37 css::awt::XRequestCallback>
39 public:
40 AsyncCallback() {}
41 AsyncCallback(const AsyncCallback&) = delete;
42 AsyncCallback& operator=(const AsyncCallback&) = delete;
44 // css::lang::XServiceInfo:
45 virtual OUString SAL_CALL getImplementationName() override;
46 virtual sal_Bool SAL_CALL supportsService(const OUString & ServiceName) override;
47 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
49 // css::awt::XRequestCallback:
50 virtual void SAL_CALL addCallback(const css::uno::Reference< css::awt::XCallback > & xCallback, const css::uno::Any & aData) override;
52 private:
54 struct CallbackData
56 CallbackData( const css::uno::Reference< css::awt::XCallback >& rCallback, const css::uno::Any& rAny ) :
57 xCallback( rCallback ), aData( rAny ) {}
59 css::uno::Reference< css::awt::XCallback > xCallback;
60 css::uno::Any const aData;
63 DECL_STATIC_LINK( AsyncCallback, Notify_Impl, void*, void );
65 virtual ~AsyncCallback() override {}
68 // com.sun.star.uno.XServiceInfo:
69 OUString SAL_CALL AsyncCallback::getImplementationName()
71 return OUString("com.sun.star.awt.comp.AsyncCallback");
74 sal_Bool SAL_CALL AsyncCallback::supportsService(OUString const & serviceName)
76 return cppu::supportsService(this, serviceName);
79 css::uno::Sequence< OUString > SAL_CALL AsyncCallback::getSupportedServiceNames()
81 css::uno::Sequence< OUString > s { "com.sun.star.awt.AsyncCallback" };
82 return s;
85 // css::awt::XRequestCallback:
86 void SAL_CALL AsyncCallback::addCallback(const css::uno::Reference< css::awt::XCallback > & xCallback, const css::uno::Any & aData)
88 if ( Application::IsInMain() )
90 // NOTE: We don't need SolarMutexGuard here as Application::PostUserEvent is thread-safe
91 CallbackData* pCallbackData = new CallbackData( xCallback, aData );
92 Application::PostUserEvent( LINK( this, AsyncCallback, Notify_Impl ), pCallbackData );
96 // private asynchronous link to call reference to the callback object
97 IMPL_STATIC_LINK( AsyncCallback, Notify_Impl, void*, p, void )
99 CallbackData* pCallbackData = static_cast<CallbackData*>(p);
102 // Asynchronous execution
103 // Check pointer and reference before!
104 if ( pCallbackData && pCallbackData->xCallback.is() )
105 pCallbackData->xCallback->notify( pCallbackData->aData );
107 catch ( css::uno::Exception& )
111 delete pCallbackData;
114 } // closing anonymous implementation namespace
116 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
117 com_sun_star_awt_comp_AsyncCallback_get_implementation(
118 css::uno::XComponentContext *,
119 css::uno::Sequence<css::uno::Any> const &)
121 return cppu::acquire(new AsyncCallback());
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */