Line data Source code
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_features.h>
21 :
22 : #include <sal/config.h>
23 :
24 : #include <boost/noncopyable.hpp>
25 :
26 : #include <toolkit/helper/accessiblefactory.hxx>
27 : #include <osl/module.h>
28 : #include <osl/diagnose.h>
29 : #include <tools/solar.h>
30 :
31 : #include "helper/accessibilityclient.hxx"
32 :
33 : namespace toolkit
34 : {
35 : using namespace ::com::sun::star::uno;
36 : using namespace ::com::sun::star::accessibility;
37 :
38 : namespace
39 : {
40 : #ifndef DISABLE_DYNLOADING
41 : static oslModule s_hAccessibleImplementationModule = NULL;
42 : #endif
43 : #if HAVE_FEATURE_DESKTOP
44 : static GetStandardAccComponentFactory s_pAccessibleFactoryFunc = NULL;
45 : #endif
46 409 : static ::rtl::Reference< IAccessibleFactory > s_pFactory;
47 : }
48 :
49 :
50 : //= AccessibleDummyFactory
51 :
52 : class AccessibleDummyFactory:
53 : public IAccessibleFactory, private boost::noncopyable
54 : {
55 : public:
56 : AccessibleDummyFactory();
57 :
58 : protected:
59 : virtual ~AccessibleDummyFactory();
60 :
61 : public:
62 : // IAccessibleFactory
63 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >
64 0 : createAccessibleContext( VCLXButton* /*_pXWindow*/ ) SAL_OVERRIDE
65 : {
66 0 : return NULL;
67 : }
68 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >
69 0 : createAccessibleContext( VCLXCheckBox* /*_pXWindow*/ ) SAL_OVERRIDE
70 : {
71 0 : return NULL;
72 : }
73 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >
74 0 : createAccessibleContext( VCLXRadioButton* /*_pXWindow*/ ) SAL_OVERRIDE
75 : {
76 0 : return NULL;
77 : }
78 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >
79 0 : createAccessibleContext( VCLXListBox* /*_pXWindow*/ ) SAL_OVERRIDE
80 : {
81 0 : return NULL;
82 : }
83 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >
84 0 : createAccessibleContext( VCLXFixedHyperlink* /*_pXWindow*/ ) SAL_OVERRIDE
85 : {
86 0 : return NULL;
87 : }
88 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >
89 0 : createAccessibleContext( VCLXFixedText* /*_pXWindow*/ ) SAL_OVERRIDE
90 : {
91 0 : return NULL;
92 : }
93 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >
94 0 : createAccessibleContext( VCLXScrollBar* /*_pXWindow*/ ) SAL_OVERRIDE
95 : {
96 0 : return NULL;
97 : }
98 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >
99 0 : createAccessibleContext( VCLXEdit* /*_pXWindow*/ ) SAL_OVERRIDE
100 : {
101 0 : return NULL;
102 : }
103 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >
104 0 : createAccessibleContext( VCLXComboBox* /*_pXWindow*/ ) SAL_OVERRIDE
105 : {
106 0 : return NULL;
107 : }
108 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >
109 0 : createAccessibleContext( VCLXToolBox* /*_pXWindow*/ ) SAL_OVERRIDE
110 : {
111 0 : return NULL;
112 : }
113 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >
114 0 : createAccessibleContext( VCLXWindow* /*_pXWindow*/ ) SAL_OVERRIDE
115 : {
116 0 : return NULL;
117 : }
118 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
119 0 : createAccessible( Menu* /*_pMenu*/, bool /*_bIsMenuBar*/ ) SAL_OVERRIDE
120 : {
121 0 : return NULL;
122 : }
123 : };
124 :
125 :
126 0 : AccessibleDummyFactory::AccessibleDummyFactory()
127 : {
128 0 : }
129 :
130 :
131 0 : AccessibleDummyFactory::~AccessibleDummyFactory()
132 : {
133 0 : }
134 :
135 :
136 : //= AccessibilityClient
137 :
138 :
139 133057 : AccessibilityClient::AccessibilityClient()
140 133057 : :m_bInitialized( false )
141 : {
142 133057 : }
143 :
144 : #if HAVE_FEATURE_DESKTOP
145 : #ifndef DISABLE_DYNLOADING
146 0 : extern "C" { static void SAL_CALL thisModule() {} }
147 : #else
148 : extern "C" void *getStandardAccessibleFactory();
149 : #endif
150 : #endif // HAVE_FEATURE_DESKTOP
151 :
152 658 : void AccessibilityClient::ensureInitialized()
153 : {
154 658 : if ( m_bInitialized )
155 694 : return;
156 :
157 622 : ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
158 :
159 : #if HAVE_FEATURE_DESKTOP
160 : // load the library implementing the factory
161 622 : if ( !s_pFactory.get() )
162 : {
163 : #ifndef DISABLE_DYNLOADING
164 20 : const OUString sModuleName( SVLIBRARY( "acc" ) );
165 20 : s_hAccessibleImplementationModule = osl_loadModuleRelative( &thisModule, sModuleName.pData, 0 );
166 20 : if ( s_hAccessibleImplementationModule != NULL )
167 : {
168 : const OUString sFactoryCreationFunc =
169 20 : OUString("getStandardAccessibleFactory");
170 : s_pAccessibleFactoryFunc = (GetStandardAccComponentFactory)
171 20 : osl_getFunctionSymbol( s_hAccessibleImplementationModule, sFactoryCreationFunc.pData );
172 :
173 : }
174 : OSL_ENSURE( s_pAccessibleFactoryFunc, "AccessibilityClient::ensureInitialized: could not load the library, or not retrieve the needed symbol!" );
175 : #else
176 : s_pAccessibleFactoryFunc = getStandardAccessibleFactory;
177 : #endif // DISABLE_DYNLOADING
178 :
179 : // get a factory instance
180 20 : if ( s_pAccessibleFactoryFunc )
181 : {
182 20 : IAccessibleFactory* pFactory = static_cast< IAccessibleFactory* >( (*s_pAccessibleFactoryFunc)() );
183 : OSL_ENSURE( pFactory, "AccessibilityClient::ensureInitialized: no factory provided by the A11Y lib!" );
184 20 : if ( pFactory )
185 : {
186 20 : s_pFactory = pFactory;
187 20 : pFactory->release();
188 : }
189 20 : }
190 : }
191 : #endif // HAVE_FEATURE_DESKTOP
192 :
193 622 : if ( !s_pFactory.get() )
194 : // the attempt to load the lib, or to create the factory, failed
195 : // -> fall back to a dummy factory
196 0 : s_pFactory = new AccessibleDummyFactory;
197 :
198 622 : m_bInitialized = true;
199 : }
200 :
201 658 : IAccessibleFactory& AccessibilityClient::getFactory()
202 : {
203 658 : ensureInitialized();
204 : OSL_ENSURE( s_pFactory.is(), "AccessibilityClient::getFactory: at least a dummy factory should have been created!" );
205 658 : return *s_pFactory;
206 : }
207 :
208 :
209 1227 : } // namespace toolkit
210 :
211 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|