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 <config_features.h>
22 #include <sal/config.h>
24 #include <boost/noncopyable.hpp>
26 #include <toolkit/helper/accessiblefactory.hxx>
27 #include <osl/module.h>
28 #include <osl/diagnose.h>
29 #include <osl/mutex.hxx>
30 #include <tools/solar.h>
32 #include "helper/accessibilityclient.hxx"
36 using namespace ::com::sun::star::uno
;
37 using namespace ::com::sun::star::accessibility
;
41 #ifndef DISABLE_DYNLOADING
42 static oslModule s_hAccessibleImplementationModule
= NULL
;
44 #if HAVE_FEATURE_DESKTOP
45 static GetStandardAccComponentFactory s_pAccessibleFactoryFunc
= NULL
;
47 static ::rtl::Reference
< IAccessibleFactory
> s_pFactory
;
51 //= AccessibleDummyFactory
53 class AccessibleDummyFactory
:
54 public IAccessibleFactory
, private boost::noncopyable
57 AccessibleDummyFactory();
60 virtual ~AccessibleDummyFactory();
64 ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleContext
>
65 createAccessibleContext( VCLXButton
* /*_pXWindow*/ ) SAL_OVERRIDE
69 ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleContext
>
70 createAccessibleContext( VCLXCheckBox
* /*_pXWindow*/ ) SAL_OVERRIDE
74 ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleContext
>
75 createAccessibleContext( VCLXRadioButton
* /*_pXWindow*/ ) SAL_OVERRIDE
79 ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleContext
>
80 createAccessibleContext( VCLXListBox
* /*_pXWindow*/ ) SAL_OVERRIDE
84 ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleContext
>
85 createAccessibleContext( VCLXFixedHyperlink
* /*_pXWindow*/ ) SAL_OVERRIDE
89 ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleContext
>
90 createAccessibleContext( VCLXFixedText
* /*_pXWindow*/ ) SAL_OVERRIDE
94 ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleContext
>
95 createAccessibleContext( VCLXScrollBar
* /*_pXWindow*/ ) SAL_OVERRIDE
99 ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleContext
>
100 createAccessibleContext( VCLXEdit
* /*_pXWindow*/ ) SAL_OVERRIDE
104 ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleContext
>
105 createAccessibleContext( VCLXComboBox
* /*_pXWindow*/ ) SAL_OVERRIDE
109 ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleContext
>
110 createAccessibleContext( VCLXToolBox
* /*_pXWindow*/ ) SAL_OVERRIDE
114 ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleContext
>
115 createAccessibleContext( VCLXWindow
* /*_pXWindow*/ ) SAL_OVERRIDE
119 ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
>
120 createAccessible( Menu
* /*_pMenu*/, bool /*_bIsMenuBar*/ ) SAL_OVERRIDE
127 AccessibleDummyFactory::AccessibleDummyFactory()
132 AccessibleDummyFactory::~AccessibleDummyFactory()
137 //= AccessibilityClient
140 AccessibilityClient::AccessibilityClient()
141 :m_bInitialized( false )
145 #if HAVE_FEATURE_DESKTOP
146 #ifndef DISABLE_DYNLOADING
147 extern "C" { static void SAL_CALL
thisModule() {} }
149 extern "C" void *getStandardAccessibleFactory();
151 #endif // HAVE_FEATURE_DESKTOP
153 void AccessibilityClient::ensureInitialized()
155 if ( m_bInitialized
)
158 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
160 #if HAVE_FEATURE_DESKTOP
161 // load the library implementing the factory
162 if ( !s_pFactory
.get() )
164 #ifndef DISABLE_DYNLOADING
165 const OUString
sModuleName( SVLIBRARY( "acc" ) );
166 s_hAccessibleImplementationModule
= osl_loadModuleRelative( &thisModule
, sModuleName
.pData
, 0 );
167 if ( s_hAccessibleImplementationModule
!= NULL
)
169 const OUString sFactoryCreationFunc
=
170 OUString("getStandardAccessibleFactory");
171 s_pAccessibleFactoryFunc
= reinterpret_cast<GetStandardAccComponentFactory
>(
172 osl_getFunctionSymbol( s_hAccessibleImplementationModule
, sFactoryCreationFunc
.pData
));
175 OSL_ENSURE( s_pAccessibleFactoryFunc
, "AccessibilityClient::ensureInitialized: could not load the library, or not retrieve the needed symbol!" );
177 s_pAccessibleFactoryFunc
= getStandardAccessibleFactory
;
178 #endif // DISABLE_DYNLOADING
180 // get a factory instance
181 if ( s_pAccessibleFactoryFunc
)
183 IAccessibleFactory
* pFactory
= static_cast< IAccessibleFactory
* >( (*s_pAccessibleFactoryFunc
)() );
184 OSL_ENSURE( pFactory
, "AccessibilityClient::ensureInitialized: no factory provided by the A11Y lib!" );
187 s_pFactory
= pFactory
;
192 #endif // HAVE_FEATURE_DESKTOP
194 if ( !s_pFactory
.get() )
195 // the attempt to load the lib, or to create the factory, failed
196 // -> fall back to a dummy factory
197 s_pFactory
= new AccessibleDummyFactory
;
199 m_bInitialized
= true;
202 IAccessibleFactory
& AccessibilityClient::getFactory()
205 OSL_ENSURE( s_pFactory
.is(), "AccessibilityClient::getFactory: at least a dummy factory should have been created!" );
210 } // namespace toolkit
212 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */