Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / toolkit / source / helper / accessibilityclient.cxx
blob773bc9bfbd060520b011b5c42596ba3458c8d097
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 <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>
34 namespace toolkit
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::accessibility;
39 namespace
41 #ifndef DISABLE_DYNLOADING
42 oslModule s_hAccessibleImplementationModule = nullptr;
43 #endif
44 #if HAVE_FEATURE_DESKTOP
45 #if !ENABLE_WASM_STRIP_ACCESSIBILITY
46 GetStandardAccComponentFactory s_pAccessibleFactoryFunc = nullptr;
47 #endif
48 #endif
49 ::rtl::Reference< IAccessibleFactory > s_pFactory;
53 //= AccessibleDummyFactory
55 namespace {
57 class AccessibleDummyFactory:
58 public IAccessibleFactory
60 public:
61 AccessibleDummyFactory();
62 AccessibleDummyFactory(const AccessibleDummyFactory&) = delete;
63 AccessibleDummyFactory& operator=(const AccessibleDummyFactory&) = delete;
65 protected:
66 virtual ~AccessibleDummyFactory() override;
68 public:
69 // IAccessibleFactory
70 css::uno::Reference< css::accessibility::XAccessibleContext >
71 createAccessibleContext( VCLXButton* /*_pXWindow*/ ) override
73 return nullptr;
75 css::uno::Reference< css::accessibility::XAccessibleContext >
76 createAccessibleContext( VCLXCheckBox* /*_pXWindow*/ ) override
78 return nullptr;
80 css::uno::Reference< css::accessibility::XAccessibleContext >
81 createAccessibleContext( VCLXRadioButton* /*_pXWindow*/ ) override
83 return nullptr;
85 css::uno::Reference< css::accessibility::XAccessibleContext >
86 createAccessibleContext( VCLXListBox* /*_pXWindow*/ ) override
88 return nullptr;
90 css::uno::Reference< css::accessibility::XAccessibleContext >
91 createAccessibleContext( VCLXFixedHyperlink* /*_pXWindow*/ ) override
93 return nullptr;
95 css::uno::Reference< css::accessibility::XAccessibleContext >
96 createAccessibleContext( VCLXFixedText* /*_pXWindow*/ ) override
98 return nullptr;
100 css::uno::Reference< css::accessibility::XAccessibleContext >
101 createAccessibleContext( VCLXScrollBar* /*_pXWindow*/ ) override
103 return nullptr;
105 css::uno::Reference< css::accessibility::XAccessibleContext >
106 createAccessibleContext( VCLXEdit* /*_pXWindow*/ ) override
108 return nullptr;
110 css::uno::Reference< css::accessibility::XAccessibleContext >
111 createAccessibleContext( VCLXComboBox* /*_pXWindow*/ ) override
113 return nullptr;
115 css::uno::Reference< css::accessibility::XAccessibleContext >
116 createAccessibleContext( VCLXToolBox* /*_pXWindow*/ ) override
118 return nullptr;
120 css::uno::Reference< css::accessibility::XAccessibleContext >
121 createAccessibleContext( VCLXHeaderBar* /*_pXWindow*/ ) override
123 return nullptr;
125 css::uno::Reference< css::accessibility::XAccessibleContext >
126 createAccessibleContext( SVTXNumericField* /*_pXWindow*/ ) override
128 return nullptr;
130 css::uno::Reference< css::accessibility::XAccessibleContext >
131 createAccessibleContext( VCLXWindow* /*_pXWindow*/ ) override
133 return nullptr;
135 css::uno::Reference< css::accessibility::XAccessible >
136 createAccessible( Menu* /*_pMenu*/, bool /*_bIsMenuBar*/ ) override
138 return nullptr;
144 AccessibleDummyFactory::AccessibleDummyFactory()
149 AccessibleDummyFactory::~AccessibleDummyFactory()
154 //= AccessibilityClient
157 AccessibilityClient::AccessibilityClient()
158 :m_bInitialized( false )
162 #if !ENABLE_WASM_STRIP_ACCESSIBILITY
163 #if HAVE_FEATURE_DESKTOP
164 #ifndef DISABLE_DYNLOADING
165 extern "C" { static void thisModule() {} }
166 #else
167 extern "C" void *getStandardAccessibleFactory();
168 #endif
169 #endif // HAVE_FEATURE_DESKTOP
170 #endif // ENABLE_WASM_STRIP_ACCESSIBILITY
172 void AccessibilityClient::ensureInitialized()
174 if ( m_bInitialized )
175 return;
177 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
179 #if !ENABLE_WASM_STRIP_ACCESSIBILITY
180 #if HAVE_FEATURE_DESKTOP
181 // load the library implementing the factory
182 if (!s_pFactory)
184 #ifndef DISABLE_DYNLOADING
185 const OUString sModuleName( SVLIBRARY( "acc" ) );
186 s_hAccessibleImplementationModule = osl_loadModuleRelative( &thisModule, sModuleName.pData, 0 );
187 if ( s_hAccessibleImplementationModule != nullptr )
189 const OUString sFactoryCreationFunc("getStandardAccessibleFactory");
190 s_pAccessibleFactoryFunc = reinterpret_cast<GetStandardAccComponentFactory>(
191 osl_getFunctionSymbol( s_hAccessibleImplementationModule, sFactoryCreationFunc.pData ));
194 OSL_ENSURE( s_pAccessibleFactoryFunc, "AccessibilityClient::ensureInitialized: could not load the library, or not retrieve the needed symbol!" );
195 #else
196 s_pAccessibleFactoryFunc = getStandardAccessibleFactory;
197 #endif // DISABLE_DYNLOADING
199 // get a factory instance
200 if ( s_pAccessibleFactoryFunc )
202 IAccessibleFactory* pFactory = static_cast< IAccessibleFactory* >( (*s_pAccessibleFactoryFunc)() );
203 OSL_ENSURE( pFactory, "AccessibilityClient::ensureInitialized: no factory provided by the A11Y lib!" );
204 if ( pFactory )
206 s_pFactory = pFactory;
207 pFactory->release();
211 #endif // HAVE_FEATURE_DESKTOP
212 #endif // ENABLE_WASM_STRIP_ACCESSIBILITY
214 if (!s_pFactory)
215 // the attempt to load the lib, or to create the factory, failed
216 // -> fall back to a dummy factory
217 s_pFactory = new AccessibleDummyFactory;
219 m_bInitialized = true;
222 IAccessibleFactory& AccessibilityClient::getFactory()
224 ensureInitialized();
225 OSL_ENSURE( s_pFactory.is(), "AccessibilityClient::getFactory: at least a dummy factory should have been created!" );
226 return *s_pFactory;
230 } // namespace toolkit
232 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */