1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "vcl/svapp.hxx"
31 #include "osl/mutex.hxx"
32 #include "sal/config.h"
33 #include "cppuhelper/factory.hxx"
34 #include "cppuhelper/implementationentry.hxx"
35 #include "cppuhelper/implbase2.hxx"
36 #include "com/sun/star/lang/XServiceInfo.hpp"
37 #include "com/sun/star/awt/XRequestCallback.hpp"
40 // component helper namespace
41 namespace comp_AsyncCallback
{
43 namespace css
= ::com::sun::star
;
45 // component and service helper functions:
46 ::rtl::OUString SAL_CALL
_getImplementationName();
47 css::uno::Sequence
< ::rtl::OUString
> SAL_CALL
_getSupportedServiceNames();
48 css::uno::Reference
< css::uno::XInterface
> SAL_CALL
_create( css::uno::Reference
< css::uno::XComponentContext
> const & context
);
50 } // closing component helper namespace
54 /// anonymous implementation namespace
57 namespace css
= ::com::sun::star
;
60 public ::cppu::WeakImplHelper2
<
61 css::lang::XServiceInfo
,
62 css::awt::XRequestCallback
>
65 explicit AsyncCallback(css::uno::Reference
< css::uno::XComponentContext
> const & context
);
67 // ::com::sun::star::lang::XServiceInfo:
68 virtual ::rtl::OUString SAL_CALL
getImplementationName() throw (css::uno::RuntimeException
);
69 virtual ::sal_Bool SAL_CALL
supportsService(const ::rtl::OUString
& ServiceName
) throw (css::uno::RuntimeException
);
70 virtual css::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedServiceNames() throw (css::uno::RuntimeException
);
72 // ::com::sun::star::awt::XRequestCallback:
73 virtual void SAL_CALL
addCallback(const css::uno::Reference
< css::awt::XCallback
> & xCallback
, const ::com::sun::star::uno::Any
& aData
) throw (css::uno::RuntimeException
);
79 CallbackData( const css::uno::Reference
< css::awt::XCallback
>& rCallback
, const css::uno::Any
& rAny
) :
80 xCallback( rCallback
), aData( rAny
) {}
82 css::uno::Reference
< css::awt::XCallback
> xCallback
;
86 DECL_STATIC_LINK( AsyncCallback
, Notify_Impl
, CallbackData
* );
88 AsyncCallback(AsyncCallback
&); // not defined
89 void operator =(AsyncCallback
&); // not defined
91 virtual ~AsyncCallback() {}
93 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
96 AsyncCallback::AsyncCallback(css::uno::Reference
< css::uno::XComponentContext
> const & context
) :
100 // com.sun.star.uno.XServiceInfo:
101 ::rtl::OUString SAL_CALL
AsyncCallback::getImplementationName() throw (css::uno::RuntimeException
)
103 return comp_AsyncCallback::_getImplementationName();
106 ::sal_Bool SAL_CALL
AsyncCallback::supportsService(::rtl::OUString
const & serviceName
) throw (css::uno::RuntimeException
)
108 const css::uno::Sequence
< ::rtl::OUString
> serviceNames
= comp_AsyncCallback::_getSupportedServiceNames();
109 for (::sal_Int32 i
= 0; i
< serviceNames
.getLength(); ++i
) {
110 if (serviceNames
[i
] == serviceName
)
116 css::uno::Sequence
< ::rtl::OUString
> SAL_CALL
AsyncCallback::getSupportedServiceNames() throw (css::uno::RuntimeException
)
118 return comp_AsyncCallback::_getSupportedServiceNames();
121 // ::com::sun::star::awt::XRequestCallback:
122 void SAL_CALL
AsyncCallback::addCallback(const css::uno::Reference
< css::awt::XCallback
> & xCallback
, const ::com::sun::star::uno::Any
& aData
) throw (css::uno::RuntimeException
)
124 if ( Application::IsInMain() )
126 SolarMutexGuard aSolarGuard
;
128 CallbackData
* pCallbackData
= new CallbackData( xCallback
, aData
);
129 Application::PostUserEvent( STATIC_LINK( this, AsyncCallback
, Notify_Impl
), pCallbackData
);
133 // private asynchronous link to call reference to the callback object
134 IMPL_STATIC_LINK_NOINSTANCE( AsyncCallback
, Notify_Impl
, CallbackData
*, pCallbackData
)
138 // Asynchronous execution
139 // Check pointer and reference before!
140 if ( pCallbackData
&& pCallbackData
->xCallback
.is() )
141 pCallbackData
->xCallback
->notify( pCallbackData
->aData
);
143 catch ( css::uno::Exception
& )
147 delete pCallbackData
;
151 } // closing anonymous implementation namespace
155 // component helper namespace
156 namespace comp_AsyncCallback
{
158 ::rtl::OUString SAL_CALL
_getImplementationName() {
159 return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
160 "com.sun.star.awt.comp.AsyncCallback"));
163 css::uno::Sequence
< ::rtl::OUString
> SAL_CALL
_getSupportedServiceNames()
165 css::uno::Sequence
< ::rtl::OUString
> s(1);
166 s
[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
167 "com.sun.star.awt.AsyncCallback"));
171 css::uno::Reference
< css::uno::XInterface
> SAL_CALL
_create(
172 const css::uno::Reference
< css::uno::XComponentContext
> & context
)
173 SAL_THROW((css::uno::Exception
))
175 return static_cast< ::cppu::OWeakObject
* >(new AsyncCallback(context
));
178 } // closing component helper namespace
180 static ::cppu::ImplementationEntry
const entries
[] = {
181 { &comp_AsyncCallback::_create
,
182 &comp_AsyncCallback::_getImplementationName
,
183 &comp_AsyncCallback::_getSupportedServiceNames
,
184 &::cppu::createSingleComponentFactory
, 0, 0 },
188 void * SAL_CALL
comp_AsyncCallback_component_getFactory(
189 const char * implName
, void * serviceManager
, void * registryKey
)
191 return ::cppu::component_getFactoryHelper(
192 implName
, serviceManager
, registryKey
, entries
);
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */