tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / toolkit / source / awt / asynccallback.cxx
blob4d5e07e47bc1fa12e692ccbc3941d6f0a5615570
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 <utility>
23 #include <vcl/svapp.hxx>
24 #include <cppuhelper/implbase.hxx>
25 #include <cppuhelper/supportsservice.hxx>
26 #include <com/sun/star/lang/XServiceInfo.hpp>
27 #include <com/sun/star/uno/XComponentContext.hpp>
28 #include <com/sun/star/awt/XRequestCallback.hpp>
30 /// anonymous implementation namespace
31 namespace {
33 class AsyncCallback:
34 public ::cppu::WeakImplHelper<
35 css::lang::XServiceInfo,
36 css::awt::XRequestCallback>
38 public:
39 AsyncCallback() {}
40 AsyncCallback(const AsyncCallback&) = delete;
41 AsyncCallback& operator=(const AsyncCallback&) = delete;
43 // css::lang::XServiceInfo:
44 virtual OUString SAL_CALL getImplementationName() override;
45 virtual sal_Bool SAL_CALL supportsService(const OUString & ServiceName) override;
46 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
48 // css::awt::XRequestCallback:
49 virtual void SAL_CALL addCallback(const css::uno::Reference< css::awt::XCallback > & xCallback, const css::uno::Any & aData) override;
51 private:
53 struct CallbackData
55 CallbackData( css::uno::Reference< css::awt::XCallback > _xCallback, css::uno::Any aAny ) :
56 xCallback(std::move( _xCallback )), aData(std::move( aAny )) {}
58 css::uno::Reference< css::awt::XCallback > xCallback;
59 css::uno::Any aData;
62 DECL_STATIC_LINK( AsyncCallback, Notify_Impl, void*, void );
64 virtual ~AsyncCallback() override {}
67 // com.sun.star.uno.XServiceInfo:
68 OUString SAL_CALL AsyncCallback::getImplementationName()
70 return u"com.sun.star.awt.comp.AsyncCallback"_ustr;
73 sal_Bool SAL_CALL AsyncCallback::supportsService(OUString const & serviceName)
75 return cppu::supportsService(this, serviceName);
78 css::uno::Sequence< OUString > SAL_CALL AsyncCallback::getSupportedServiceNames()
80 return { u"com.sun.star.awt.AsyncCallback"_ustr };
83 // css::awt::XRequestCallback:
84 void SAL_CALL AsyncCallback::addCallback(const css::uno::Reference< css::awt::XCallback > & xCallback, const css::uno::Any & aData)
86 if ( Application::IsInMain() )
88 // NOTE: We don't need SolarMutexGuard here as Application::PostUserEvent is thread-safe
89 CallbackData* pCallbackData = new CallbackData( xCallback, aData );
90 Application::PostUserEvent( LINK( this, AsyncCallback, Notify_Impl ), pCallbackData );
94 // private asynchronous link to call reference to the callback object
95 IMPL_STATIC_LINK( AsyncCallback, Notify_Impl, void*, p, void )
97 CallbackData* pCallbackData = static_cast<CallbackData*>(p);
98 try
100 // Asynchronous execution
101 // Check pointer and reference before!
102 if ( pCallbackData && pCallbackData->xCallback.is() )
103 pCallbackData->xCallback->notify( pCallbackData->aData );
105 catch ( css::uno::Exception& )
109 delete pCallbackData;
112 } // closing anonymous implementation namespace
114 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
115 com_sun_star_awt_comp_AsyncCallback_get_implementation(
116 css::uno::XComponentContext *,
117 css::uno::Sequence<css::uno::Any> const &)
119 return cppu::acquire(new AsyncCallback());
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */