summaryrefslogtreecommitdiffstats
path: root/vcl/source/helper/svtaccessiblefactory.cxx
blob: 5b966d48620caf4b631294a250d449666c4e0723 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <config_feature_desktop.h>

#include <vcl/svtaccessiblefactory.hxx>
#include <vcl/accessiblefactory.hxx>

#include <tools/svlibrary.h>
#include <tools/debug.hxx>

#include <osl/module.h>
#include <osl/diagnose.h>
#include <rtl/ref.hxx>

namespace vcl
{
    using namespace ::com::sun::star::uno;
    using namespace ::com::sun::star::awt;
    using namespace ::com::sun::star::accessibility;

    namespace
    {
#ifndef DISABLE_DYNLOADING
        static oslModule                                s_hAccessibleImplementationModule = nullptr;
#endif
#if HAVE_FEATURE_DESKTOP
        static GetSvtAccessibilityComponentFactory      s_pAccessibleFactoryFunc = nullptr;
#endif
        static ::rtl::Reference< IAccessibleFactory >   s_pFactory;


        //= AccessibleDummyFactory

        class AccessibleDummyFactory:
            public IAccessibleFactory
        {
        public:
            AccessibleDummyFactory();
            AccessibleDummyFactory(const AccessibleDummyFactory&) = delete;
            AccessibleDummyFactory& operator=(const AccessibleDummyFactory&) = delete;

        protected:
            virtual ~AccessibleDummyFactory() override;

        public:
            // IAccessibleFactory
            virtual vcl::IAccessibleTabListBox*
                createAccessibleTabListBox(
                    const css::uno::Reference< css::accessibility::XAccessible >& /*rxParent*/,
                    SvHeaderTabListBox& /*rBox*/
                ) const override
            {
                return nullptr;
            }

            virtual css::uno::Reference< css::accessibility::XAccessible >
                createAccessibleTreeListBox(
                    SvTreeListBox& /*_rListBox*/,
                    const css::uno::Reference< css::accessibility::XAccessible >& /*_xParent*/
                ) const override
            {
                return nullptr;
            }

            virtual vcl::IAccessibleBrowseBox*
                createAccessibleBrowseBox(
                    const css::uno::Reference< css::accessibility::XAccessible >& /*_rxParent*/,
                    vcl::IAccessibleTableProvider& /*_rBrowseBox*/
                ) const override
            {
                return nullptr;
            }

            virtual table::IAccessibleTableControl*
                createAccessibleTableControl(
                    const css::uno::Reference< css::accessibility::XAccessible >& /*_rxParent*/,
                    table::IAccessibleTable& /*_rTable*/
                ) const override
            {
                return nullptr;
            }

            virtual css::uno::Reference< css::accessibility::XAccessible >
                createAccessibleIconChoiceCtrl(
                    SvtIconChoiceCtrl& /*_rIconCtrl*/,
                    const css::uno::Reference< css::accessibility::XAccessible >& /*_xParent*/
                ) const override
            {
                return nullptr;
            }

            virtual css::uno::Reference< css::accessibility::XAccessible >
                createAccessibleTabBar(
                    TabBar& /*_rTabBar*/
                ) const override
            {
                return nullptr;
            }

            virtual css::uno::Reference< css::accessibility::XAccessibleContext >
                createAccessibleTextWindowContext(
                    VCLXWindow* /*pVclXWindow*/, TextEngine& /*rEngine*/, TextView& /*rView*/
                ) const override
            {
                return nullptr;
            }

            virtual css::uno::Reference< css::accessibility::XAccessible >
                createAccessibleBrowseBoxHeaderBar(
                    const css::uno::Reference< css::accessibility::XAccessible >& /*rxParent*/,
                    vcl::IAccessibleTableProvider& /*_rOwningTable*/,
                    vcl::AccessibleBrowseBoxObjType /*_eObjType*/
                ) const override
            {
                return nullptr;
            }

            virtual css::uno::Reference< css::accessibility::XAccessible >
                createAccessibleBrowseBoxTableCell(
                    const css::uno::Reference< css::accessibility::XAccessible >& /*_rxParent*/,
                    vcl::IAccessibleTableProvider& /*_rBrowseBox*/,
                    const css::uno::Reference< css::awt::XWindow >& /*_xFocusWindow*/,
                    sal_Int32 /*_nRowId*/,
                    sal_uInt16 /*_nColId*/,
                    sal_Int32 /*_nOffset*/
                ) const override
            {
                return nullptr;
            }

            virtual css::uno::Reference< css::accessibility::XAccessible >
                createAccessibleBrowseBoxHeaderCell(
                    sal_Int32 /*_nColumnRowId*/,
                    const css::uno::Reference< css::accessibility::XAccessible >& /*rxParent*/,
                    vcl::IAccessibleTableProvider& /*_rBrowseBox*/,
                    const css::uno::Reference< css::awt::XWindow >& /*_xFocusWindow*/,
                    vcl::AccessibleBrowseBoxObjType  /*_eObjType*/
                ) const override
            {
                return nullptr;
            }

            virtual css::uno::Reference< css::accessibility::XAccessible >
                createAccessibleCheckBoxCell(
                    const css::uno::Reference< css::accessibility::XAccessible >& /*_rxParent*/,
                    vcl::IAccessibleTableProvider& /*_rBrowseBox*/,
                    const css::uno::Reference< css::awt::XWindow >& /*_xFocusWindow*/,
                    sal_Int32 /*_nRowPos*/,
                    sal_uInt16 /*_nColPos*/,
                    const TriState& /*_eState*/,
                    bool /*_bIsTriState*/
                ) const override
            {
                return nullptr;
            }

            virtual css::uno::Reference< css::accessibility::XAccessible >
                createEditBrowseBoxTableCellAccess(
                    const css::uno::Reference< css::accessibility::XAccessible >& /*_rxParent*/,
                    const css::uno::Reference< css::accessibility::XAccessible >& /*_rxControlAccessible*/,
                    const css::uno::Reference< css::awt::XWindow >& /*_rxFocusWindow*/,
                    vcl::IAccessibleTableProvider& /*_rBrowseBox*/,
                    sal_Int32 /*_nRowPos*/,
                    sal_uInt16 /*_nColPos*/
                ) const override
            {
                return nullptr;
            }
        };


        AccessibleDummyFactory::AccessibleDummyFactory()
        {
        }


        AccessibleDummyFactory::~AccessibleDummyFactory()
        {
        }

    }


    //= AccessibleFactoryAccess


    AccessibleFactoryAccess::AccessibleFactoryAccess()
        :m_bInitialized( false )
    {
    }

#if HAVE_FEATURE_DESKTOP
#ifndef DISABLE_DYNLOADING
    extern "C" { static void thisModule() {} }
#else
    extern "C" void* getSvtAccessibilityComponentFactory();
#endif
#endif // HAVE_FEATURE_DESKTOP

    void AccessibleFactoryAccess::ensureInitialized()
    {
        if ( m_bInitialized )
            return;

        ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );

#if HAVE_FEATURE_DESKTOP
        // load the library implementing the factory
        if (!s_pFactory)
        {
#ifndef DISABLE_DYNLOADING
            const OUString sModuleName( SVLIBRARY( "acc" ));
            s_hAccessibleImplementationModule = osl_loadModuleRelative( &thisModule, sModuleName.pData, 0 );
            if ( s_hAccessibleImplementationModule != nullptr )
            {
                const OUString sFactoryCreationFunc( "getSvtAccessibilityComponentFactory" );
                s_pAccessibleFactoryFunc = reinterpret_cast<GetSvtAccessibilityComponentFactory>(
                    osl_getFunctionSymbol( s_hAccessibleImplementationModule, sFactoryCreationFunc.pData ));

            }
            OSL_ENSURE( s_pAccessibleFactoryFunc, "ac_registerClient: could not load the library, or not retrieve the needed symbol!" );
#else
            s_pAccessibleFactoryFunc = getSvtAccessibilityComponentFactory;
#endif // DISABLE_DYNLOADING

            // get a factory instance
            if ( s_pAccessibleFactoryFunc )
            {
                IAccessibleFactory* pFactory = static_cast< IAccessibleFactory* >( (*s_pAccessibleFactoryFunc)() );
                if ( pFactory )
                {
                    s_pFactory = pFactory;
                    pFactory->release();
                }
            }
        }
#endif // HAVE_FEATURE_DESKTOP

        if (!s_pFactory)
            // the attempt to load the lib, or to create the factory, failed
            // -> fall back to a dummy factory
            s_pFactory = new AccessibleDummyFactory;

        m_bInitialized = true;
    }

    IAccessibleFactory& AccessibleFactoryAccess::getFactory()
    {
        ensureInitialized();
        DBG_ASSERT( s_pFactory.is(), "AccessibleFactoryAccess::getFactory: at least a dummy factory should have been created!" );
        return *s_pFactory;
    }

}   // namespace vcl

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */