LibreOffice Module toolkit (master) 1
accessibilityclient.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <config_feature_desktop.h>
21#include <config_wasm_strip.h>
22
23#include <sal/config.h>
24
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>
31
33
34namespace toolkit
35{
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::accessibility;
38
39 namespace
40 {
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
50 }
51
52
53 //= AccessibleDummyFactory
54
55 namespace {
56
57 class AccessibleDummyFactory:
58 public IAccessibleFactory
59 {
60 public:
61 AccessibleDummyFactory();
62 AccessibleDummyFactory(const AccessibleDummyFactory&) = delete;
63 AccessibleDummyFactory& operator=(const AccessibleDummyFactory&) = delete;
64
65 protected:
66 virtual ~AccessibleDummyFactory() override;
67
68 public:
69 // IAccessibleFactory
70 css::uno::Reference< css::accessibility::XAccessibleContext >
71 createAccessibleContext( VCLXButton* /*_pXWindow*/ ) override
72 {
73 return nullptr;
74 }
75 css::uno::Reference< css::accessibility::XAccessibleContext >
76 createAccessibleContext( VCLXCheckBox* /*_pXWindow*/ ) override
77 {
78 return nullptr;
79 }
80 css::uno::Reference< css::accessibility::XAccessibleContext >
81 createAccessibleContext( VCLXRadioButton* /*_pXWindow*/ ) override
82 {
83 return nullptr;
84 }
85 css::uno::Reference< css::accessibility::XAccessibleContext >
86 createAccessibleContext( VCLXListBox* /*_pXWindow*/ ) override
87 {
88 return nullptr;
89 }
90 css::uno::Reference< css::accessibility::XAccessibleContext >
91 createAccessibleContext( VCLXFixedHyperlink* /*_pXWindow*/ ) override
92 {
93 return nullptr;
94 }
95 css::uno::Reference< css::accessibility::XAccessibleContext >
96 createAccessibleContext( VCLXFixedText* /*_pXWindow*/ ) override
97 {
98 return nullptr;
99 }
100 css::uno::Reference< css::accessibility::XAccessibleContext >
101 createAccessibleContext( VCLXScrollBar* /*_pXWindow*/ ) override
102 {
103 return nullptr;
104 }
105 css::uno::Reference< css::accessibility::XAccessibleContext >
106 createAccessibleContext( VCLXEdit* /*_pXWindow*/ ) override
107 {
108 return nullptr;
109 }
110 css::uno::Reference< css::accessibility::XAccessibleContext >
111 createAccessibleContext( VCLXComboBox* /*_pXWindow*/ ) override
112 {
113 return nullptr;
114 }
115 css::uno::Reference< css::accessibility::XAccessibleContext >
116 createAccessibleContext( VCLXToolBox* /*_pXWindow*/ ) override
117 {
118 return nullptr;
119 }
120 css::uno::Reference< css::accessibility::XAccessibleContext >
121 createAccessibleContext( VCLXHeaderBar* /*_pXWindow*/ ) override
122 {
123 return nullptr;
124 }
125 css::uno::Reference< css::accessibility::XAccessibleContext >
126 createAccessibleContext( SVTXNumericField* /*_pXWindow*/ ) override
127 {
128 return nullptr;
129 }
130 css::uno::Reference< css::accessibility::XAccessibleContext >
131 createAccessibleContext( VCLXWindow* /*_pXWindow*/ ) override
132 {
133 return nullptr;
134 }
135 css::uno::Reference< css::accessibility::XAccessible >
136 createAccessible( Menu* /*_pMenu*/, bool /*_bIsMenuBar*/ ) override
137 {
138 return nullptr;
139 }
140 };
141
142 }
143
144 AccessibleDummyFactory::AccessibleDummyFactory()
145 {
146 }
147
148
149 AccessibleDummyFactory::~AccessibleDummyFactory()
150 {
151 }
152
153
154 //= AccessibilityClient
155
156
158 :m_bInitialized( false )
159 {
160 }
161
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
171
173 {
174 if ( m_bInitialized )
175 return;
176
177 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
178
179#if !ENABLE_WASM_STRIP_ACCESSIBILITY
180#if HAVE_FEATURE_DESKTOP
181 // load the library implementing the factory
182 if (!s_pFactory)
183 {
184#ifndef DISABLE_DYNLOADING
185 const OUString sModuleName( SVLIBRARY( "acc" ) );
186 s_hAccessibleImplementationModule = osl_loadModuleRelative( &thisModule, sModuleName.pData, 0 );
187 if ( s_hAccessibleImplementationModule != nullptr )
188 {
189 const OUString sFactoryCreationFunc("getStandardAccessibleFactory");
190 s_pAccessibleFactoryFunc = reinterpret_cast<GetStandardAccComponentFactory>(
191 osl_getFunctionSymbol( s_hAccessibleImplementationModule, sFactoryCreationFunc.pData ));
192
193 }
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
198
199 // get a factory instance
200 if ( s_pAccessibleFactoryFunc )
201 {
202 IAccessibleFactory* pFactory = static_cast< IAccessibleFactory* >( (*s_pAccessibleFactoryFunc)() );
203 OSL_ENSURE( pFactory, "AccessibilityClient::ensureInitialized: no factory provided by the A11Y lib!" );
204 if ( pFactory )
205 {
206 s_pFactory = pFactory;
207 pFactory->release();
208 }
209 }
210 }
211#endif // HAVE_FEATURE_DESKTOP
212#endif // ENABLE_WASM_STRIP_ACCESSIBILITY
213
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;
218
219 m_bInitialized = true;
220 }
221
223 {
225 OSL_ENSURE( s_pFactory.is(), "AccessibilityClient::getFactory: at least a dummy factory should have been created!" );
226 return *s_pFactory;
227 }
228
229
230} // namespace toolkit
231
232/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
IAccessibleFactory & getFactory()
void *(* GetStandardAccComponentFactory)()
a function which is able to create a factory for the standard Accessible/Context components needed fo...
#define SVLIBRARY(Base)