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_feature_desktop.h>
21 #include <config_wasm_strip.h>
23 #include <sal/config.h>
25 #include <toolkit/helper/accessiblefactory.hxx>
26 #include <osl/module.h>
27 #include <osl/diagnose.h>
28 #include <osl/mutex.hxx>
29 #include <rtl/ref.hxx>
30 #include <tools/svlibrary.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 oslModule s_hAccessibleImplementationModule
= nullptr;
44 #if HAVE_FEATURE_DESKTOP
45 #if !ENABLE_WASM_STRIP_ACCESSIBILITY
46 GetStandardAccComponentFactory s_pAccessibleFactoryFunc
= nullptr;
49 ::rtl::Reference
< IAccessibleFactory
> s_pFactory
;
53 //= AccessibleDummyFactory
57 class AccessibleDummyFactory
:
58 public IAccessibleFactory
61 AccessibleDummyFactory();
62 AccessibleDummyFactory(const AccessibleDummyFactory
&) = delete;
63 AccessibleDummyFactory
& operator=(const AccessibleDummyFactory
&) = delete;
66 virtual ~AccessibleDummyFactory() override
;
70 css::uno::Reference
< css::accessibility::XAccessibleContext
>
71 createAccessibleContext( VCLXButton
* /*_pXWindow*/ ) override
75 css::uno::Reference
< css::accessibility::XAccessibleContext
>
76 createAccessibleContext( VCLXCheckBox
* /*_pXWindow*/ ) override
80 css::uno::Reference
< css::accessibility::XAccessibleContext
>
81 createAccessibleContext( VCLXRadioButton
* /*_pXWindow*/ ) override
85 css::uno::Reference
< css::accessibility::XAccessibleContext
>
86 createAccessibleContext( VCLXListBox
* /*_pXWindow*/ ) override
90 css::uno::Reference
< css::accessibility::XAccessibleContext
>
91 createAccessibleContext( VCLXFixedHyperlink
* /*_pXWindow*/ ) override
95 css::uno::Reference
< css::accessibility::XAccessibleContext
>
96 createAccessibleContext( VCLXFixedText
* /*_pXWindow*/ ) override
100 css::uno::Reference
< css::accessibility::XAccessibleContext
>
101 createAccessibleContext( VCLXScrollBar
* /*_pXWindow*/ ) override
105 css::uno::Reference
< css::accessibility::XAccessibleContext
>
106 createAccessibleContext( VCLXEdit
* /*_pXWindow*/ ) override
110 css::uno::Reference
< css::accessibility::XAccessibleContext
>
111 createAccessibleContext( VCLXMultiLineEdit
* /*_pXWindow*/ ) override
115 css::uno::Reference
< css::accessibility::XAccessibleContext
>
116 createAccessibleContext( VCLXComboBox
* /*_pXWindow*/ ) override
120 css::uno::Reference
< css::accessibility::XAccessibleContext
>
121 createAccessibleContext( VCLXToolBox
* /*_pXWindow*/ ) override
125 css::uno::Reference
< css::accessibility::XAccessibleContext
>
126 createAccessibleContext( VCLXHeaderBar
* /*_pXWindow*/ ) override
130 css::uno::Reference
< css::accessibility::XAccessibleContext
>
131 createAccessibleContext( SVTXNumericField
* /*_pXWindow*/ ) override
135 css::uno::Reference
< css::accessibility::XAccessibleContext
>
136 createAccessibleContext( VCLXWindow
* /*_pXWindow*/ ) override
140 css::uno::Reference
< css::accessibility::XAccessible
>
141 createAccessible( Menu
* /*_pMenu*/, bool /*_bIsMenuBar*/ ) override
149 AccessibleDummyFactory::AccessibleDummyFactory()
154 AccessibleDummyFactory::~AccessibleDummyFactory()
159 //= AccessibilityClient
162 AccessibilityClient::AccessibilityClient()
163 :m_bInitialized( false )
167 #if !ENABLE_WASM_STRIP_ACCESSIBILITY
168 #if HAVE_FEATURE_DESKTOP
169 #ifndef DISABLE_DYNLOADING
170 extern "C" { static void thisModule() {} }
172 extern "C" void *getStandardAccessibleFactory();
174 #endif // HAVE_FEATURE_DESKTOP
175 #endif // ENABLE_WASM_STRIP_ACCESSIBILITY
177 void AccessibilityClient::ensureInitialized()
179 if ( m_bInitialized
)
182 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
184 #if !ENABLE_WASM_STRIP_ACCESSIBILITY
185 #if HAVE_FEATURE_DESKTOP
186 // load the library implementing the factory
189 #ifndef DISABLE_DYNLOADING
190 s_hAccessibleImplementationModule
= osl_loadModuleRelative( &thisModule
, u
"" SVLIBRARY( "acc" ) ""_ustr
.pData
, 0 );
191 if ( s_hAccessibleImplementationModule
!= nullptr )
193 s_pAccessibleFactoryFunc
= reinterpret_cast<GetStandardAccComponentFactory
>(
194 osl_getFunctionSymbol( s_hAccessibleImplementationModule
, u
"getStandardAccessibleFactory"_ustr
.pData
));
197 OSL_ENSURE( s_pAccessibleFactoryFunc
, "AccessibilityClient::ensureInitialized: could not load the library, or not retrieve the needed symbol!" );
199 s_pAccessibleFactoryFunc
= getStandardAccessibleFactory
;
200 #endif // DISABLE_DYNLOADING
202 // get a factory instance
203 if ( s_pAccessibleFactoryFunc
)
205 IAccessibleFactory
* pFactory
= static_cast< IAccessibleFactory
* >( (*s_pAccessibleFactoryFunc
)() );
206 OSL_ENSURE( pFactory
, "AccessibilityClient::ensureInitialized: no factory provided by the A11Y lib!" );
209 s_pFactory
= pFactory
;
214 #endif // HAVE_FEATURE_DESKTOP
215 #endif // ENABLE_WASM_STRIP_ACCESSIBILITY
218 // the attempt to load the lib, or to create the factory, failed
219 // -> fall back to a dummy factory
220 s_pFactory
= new AccessibleDummyFactory
;
222 m_bInitialized
= true;
225 IAccessibleFactory
& AccessibilityClient::getFactory()
228 OSL_ENSURE( s_pFactory
.is(), "AccessibilityClient::getFactory: at least a dummy factory should have been created!" );
233 } // namespace toolkit
235 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */