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_features.h>
21 #include <config_feature_desktop.h>
23 #include <cppuhelper/supportsservice.hxx>
24 #include <toolkit/awt/vclxwindows.hxx>
25 #include <toolkit/helper/accessiblefactory.hxx>
26 #include <vcl/accessiblefactory.hxx>
27 #include <standard/svtaccessiblenumericfield.hxx>
28 #include <standard/vclxaccessiblebutton.hxx>
29 #include <standard/vclxaccessiblecheckbox.hxx>
30 #include <standard/vclxaccessibledropdowncombobox.hxx>
31 #include <standard/vclxaccessiblecombobox.hxx>
32 #include <standard/vclxaccessibledropdownlistbox.hxx>
33 #include <standard/vclxaccessibleedit.hxx>
34 #include <standard/vclxaccessiblefixedhyperlink.hxx>
35 #include <standard/vclxaccessiblefixedtext.hxx>
36 #include <standard/vclxaccessibleheaderbar.hxx>
37 #include <standard/vclxaccessiblelistbox.hxx>
38 #include <standard/vclxaccessibleradiobutton.hxx>
39 #include <standard/vclxaccessiblescrollbar.hxx>
40 #include <standard/vclxaccessibletoolbox.hxx>
41 #include <toolkit/awt/vclxaccessiblecomponent.hxx>
42 #include <standard/vclxaccessiblestatusbar.hxx>
43 #include <standard/vclxaccessibletabcontrol.hxx>
44 #include <standard/vclxaccessibletabpagewindow.hxx>
45 #include <standard/vclxaccessiblemenubar.hxx>
46 #include <standard/vclxaccessiblepopupmenu.hxx>
47 #include <extended/accessibletablistbox.hxx>
48 #include <extended/AccessibleBrowseBox.hxx>
49 #include <extended/accessibleiconchoicectrl.hxx>
50 #include <extended/AccessibleIconView.hxx>
51 #include <extended/accessibletabbar.hxx>
52 #include <extended/accessiblelistbox.hxx>
53 #include <extended/AccessibleBrowseBoxHeaderBar.hxx>
54 #include <extended/textwindowaccessibility.hxx>
55 #include <extended/AccessibleBrowseBoxTableCell.hxx>
56 #include <extended/AccessibleBrowseBoxHeaderCell.hxx>
57 #include <extended/AccessibleBrowseBoxCheckBoxCell.hxx>
58 #include <extended/accessibleeditbrowseboxcell.hxx>
59 #include <com/sun/star/accessibility/AccessibleRole.hpp>
60 #include <vcl/toolkit/lstbox.hxx>
61 #include <vcl/toolkit/combobox.hxx>
62 #include <extended/AccessibleGridControl.hxx>
63 #include <vcl/accessibletable.hxx>
65 #include <floatingwindowaccessible.hxx>
67 using namespace ::accessibility
;
68 using namespace ::com::sun::star::uno
;
69 using namespace ::com::sun::star::awt
;
70 using namespace ::com::sun::star::accessibility
;
71 using namespace ::vcl
;
72 using namespace ::vcl::table
;
76 bool hasFloatingChild(vcl::Window
*pWindow
)
78 vcl::Window
* pChild
= pWindow
->GetAccessibleChildWindow(0);
79 return pChild
&& pChild
->GetType() == WindowType::FLOATINGWINDOW
;
83 class AccessibleFactory
:public ::toolkit::IAccessibleFactory
84 ,public ::vcl::IAccessibleFactory
89 // ::toolkit::IAccessibleFactory
90 virtual css::uno::Reference
< css::accessibility::XAccessibleContext
>
91 createAccessibleContext( VCLXButton
* _pXWindow
) override
;
92 virtual css::uno::Reference
< css::accessibility::XAccessibleContext
>
93 createAccessibleContext( VCLXCheckBox
* _pXWindow
) override
;
94 virtual css::uno::Reference
< css::accessibility::XAccessibleContext
>
95 createAccessibleContext( VCLXRadioButton
* _pXWindow
) override
;
96 virtual css::uno::Reference
< css::accessibility::XAccessibleContext
>
97 createAccessibleContext( VCLXListBox
* _pXWindow
) override
;
98 virtual css::uno::Reference
< css::accessibility::XAccessibleContext
>
99 createAccessibleContext( VCLXFixedText
* _pXWindow
) override
;
100 virtual css::uno::Reference
< css::accessibility::XAccessibleContext
>
101 createAccessibleContext( VCLXFixedHyperlink
* _pXWindow
) override
;
102 virtual css::uno::Reference
< css::accessibility::XAccessibleContext
>
103 createAccessibleContext( VCLXScrollBar
* _pXWindow
) override
;
104 virtual css::uno::Reference
< css::accessibility::XAccessibleContext
>
105 createAccessibleContext( VCLXEdit
* _pXWindow
) override
;
106 virtual css::uno::Reference
< css::accessibility::XAccessibleContext
>
107 createAccessibleContext( VCLXMultiLineEdit
* _pXWindow
) override
;
108 virtual css::uno::Reference
< css::accessibility::XAccessibleContext
>
109 createAccessibleContext( VCLXComboBox
* _pXWindow
) override
;
110 virtual css::uno::Reference
< css::accessibility::XAccessibleContext
>
111 createAccessibleContext( VCLXToolBox
* _pXWindow
) override
;
112 virtual css::uno::Reference
< css::accessibility::XAccessibleContext
>
113 createAccessibleContext( VCLXHeaderBar
* _pXWindow
) override
;
114 virtual css::uno::Reference
< css::accessibility::XAccessibleContext
>
115 createAccessibleContext( SVTXNumericField
* _pXWindow
) override
;
116 virtual css::uno::Reference
< css::accessibility::XAccessibleContext
>
117 createAccessibleContext( VCLXWindow
* _pXWindow
) override
;
118 virtual css::uno::Reference
< css::accessibility::XAccessible
>
119 createAccessible( Menu
* _pMenu
, bool _bIsMenuBar
) override
;
121 // ::vcl::IAccessibleFactory
122 virtual vcl::IAccessibleTabListBox
*
123 createAccessibleTabListBox(
124 const css::uno::Reference
< css::accessibility::XAccessible
>& rxParent
,
125 SvHeaderTabListBox
& rBox
128 virtual rtl::Reference
<vcl::IAccessibleBrowseBox
>
129 createAccessibleBrowseBox(
130 const css::uno::Reference
< css::accessibility::XAccessible
>& _rxParent
,
131 vcl::IAccessibleTableProvider
& _rBrowseBox
134 virtual rtl::Reference
<IAccessibleTableControl
>
135 createAccessibleTableControl(
136 const css::uno::Reference
< css::accessibility::XAccessible
>& _rxParent
,
137 IAccessibleTable
& _rTable
140 virtual css::uno::Reference
< css::accessibility::XAccessible
>
141 createAccessibleIconChoiceCtrl(
142 SvtIconChoiceCtrl
& _rIconCtrl
,
143 const css::uno::Reference
< css::accessibility::XAccessible
>& _xParent
146 virtual css::uno::Reference
< css::accessibility::XAccessible
>
147 createAccessibleTabBar(
151 virtual css::uno::Reference
< css::accessibility::XAccessibleContext
>
152 createAccessibleTextWindowContext(
153 VCLXWindow
* pVclXWindow
, TextEngine
& rEngine
, TextView
& rView
156 virtual css::uno::Reference
< css::accessibility::XAccessible
>
157 createAccessibleTreeListBox(
158 SvTreeListBox
& _rListBox
,
159 const css::uno::Reference
< css::accessibility::XAccessible
>& _xParent
162 virtual css::uno::Reference
< css::accessibility::XAccessible
>
163 createAccessibleIconView(
164 SvTreeListBox
& _rListBox
,
165 const css::uno::Reference
< css::accessibility::XAccessible
>& _xParent
168 virtual css::uno::Reference
< css::accessibility::XAccessible
>
169 createAccessibleBrowseBoxHeaderBar(
170 const css::uno::Reference
< css::accessibility::XAccessible
>& rxParent
,
171 vcl::IAccessibleTableProvider
& _rOwningTable
,
172 AccessibleBrowseBoxObjType _eObjType
175 virtual css::uno::Reference
< css::accessibility::XAccessible
>
176 createAccessibleBrowseBoxTableCell(
177 const css::uno::Reference
< css::accessibility::XAccessible
>& _rxParent
,
178 vcl::IAccessibleTableProvider
& _rBrowseBox
,
179 const css::uno::Reference
< css::awt::XWindow
>& _xFocusWindow
,
185 virtual css::uno::Reference
< css::accessibility::XAccessible
>
186 createAccessibleBrowseBoxHeaderCell(
187 sal_Int32 _nColumnRowId
,
188 const css::uno::Reference
< css::accessibility::XAccessible
>& rxParent
,
189 vcl::IAccessibleTableProvider
& _rBrowseBox
,
190 const css::uno::Reference
< css::awt::XWindow
>& _xFocusWindow
,
191 AccessibleBrowseBoxObjType _eObjType
194 virtual css::uno::Reference
< css::accessibility::XAccessible
>
195 createAccessibleCheckBoxCell(
196 const css::uno::Reference
< css::accessibility::XAccessible
>& _rxParent
,
197 vcl::IAccessibleTableProvider
& _rBrowseBox
,
198 const css::uno::Reference
< css::awt::XWindow
>& _xFocusWindow
,
201 const TriState
& _eState
,
205 virtual css::uno::Reference
< css::accessibility::XAccessible
>
206 createEditBrowseBoxTableCellAccess(
207 const css::uno::Reference
< css::accessibility::XAccessible
>& _rxParent
,
208 const css::uno::Reference
< css::accessibility::XAccessible
>& _rxControlAccessible
,
209 const css::uno::Reference
< css::awt::XWindow
>& _rxFocusWindow
,
210 vcl::IAccessibleTableProvider
& _rBrowseBox
,
216 virtual ~AccessibleFactory() override
;
219 AccessibleFactory::AccessibleFactory()
223 AccessibleFactory::~AccessibleFactory()
227 Reference
< XAccessible
> AccessibleFactory::createAccessible( Menu
* _pMenu
, bool _bIsMenuBar
)
229 rtl::Reference
<OAccessibleMenuBaseComponent
> pAccessible
;
231 pAccessible
= new VCLXAccessibleMenuBar( _pMenu
);
233 pAccessible
= new VCLXAccessiblePopupMenu( _pMenu
);
234 pAccessible
->SetStates();
238 Reference
< XAccessibleContext
> AccessibleFactory::createAccessibleContext( VCLXButton
* _pXWindow
)
240 return new VCLXAccessibleButton( _pXWindow
);
243 Reference
< XAccessibleContext
> AccessibleFactory::createAccessibleContext( VCLXCheckBox
* _pXWindow
)
245 return new VCLXAccessibleCheckBox( _pXWindow
);
248 Reference
< XAccessibleContext
> AccessibleFactory::createAccessibleContext( VCLXRadioButton
* _pXWindow
)
250 return new VCLXAccessibleRadioButton( _pXWindow
);
253 Reference
< XAccessibleContext
> AccessibleFactory::createAccessibleContext( VCLXListBox
* _pXWindow
)
255 bool bIsDropDownBox
= false;
256 VclPtr
< ListBox
> pBox
= _pXWindow
->GetAs
< ListBox
>();
258 bIsDropDownBox
= ( ( pBox
->GetStyle() & WB_DROPDOWN
) == WB_DROPDOWN
);
260 if ( bIsDropDownBox
)
261 return new VCLXAccessibleDropDownListBox( _pXWindow
);
263 return new VCLXAccessibleListBox( _pXWindow
);
266 Reference
< XAccessibleContext
> AccessibleFactory::createAccessibleContext( VCLXFixedText
* _pXWindow
)
268 return new VCLXAccessibleFixedText( _pXWindow
);
271 Reference
< XAccessibleContext
> AccessibleFactory::createAccessibleContext( VCLXFixedHyperlink
* _pXWindow
)
273 return new VCLXAccessibleFixedHyperlink( _pXWindow
);
276 Reference
< XAccessibleContext
> AccessibleFactory::createAccessibleContext( VCLXScrollBar
* _pXWindow
)
278 return new VCLXAccessibleScrollBar( _pXWindow
);
281 Reference
< XAccessibleContext
> AccessibleFactory::createAccessibleContext( VCLXEdit
* _pXWindow
)
283 return new VCLXAccessibleEdit( _pXWindow
);
286 Reference
< XAccessibleContext
> AccessibleFactory::createAccessibleContext( VCLXMultiLineEdit
* _pXWindow
)
288 return new VCLXAccessibleEdit( _pXWindow
);
291 Reference
< XAccessibleContext
> AccessibleFactory::createAccessibleContext( VCLXComboBox
* _pXWindow
)
293 bool bIsDropDownBox
= false;
294 VclPtr
< ComboBox
> pBox
= _pXWindow
->GetAs
< ComboBox
>();
296 bIsDropDownBox
= ( ( pBox
->GetStyle() & WB_DROPDOWN
) == WB_DROPDOWN
);
298 if ( bIsDropDownBox
)
299 return new VCLXAccessibleDropDownComboBox( _pXWindow
);
301 return new VCLXAccessibleComboBox( _pXWindow
);
304 Reference
< XAccessibleContext
> AccessibleFactory::createAccessibleContext( VCLXWindow
* _pXWindow
)
306 VclPtr
<vcl::Window
> pWindow
= _pXWindow
->GetWindow();
309 WindowType nType
= pWindow
->GetType();
311 if ( nType
== WindowType::MENUBARWINDOW
|| pWindow
->IsMenuFloatingWindow() || pWindow
->IsToolbarFloatingWindow() )
313 Reference
< XAccessible
> xAcc( pWindow
->GetAccessible() );
316 Reference
<XAccessibleContext
> xContext(xAcc
->getAccessibleContext());
317 if ( pWindow
->GetType() == WindowType::MENUBARWINDOW
||
318 ( xContext
.is() && xContext
->getAccessibleRole() == AccessibleRole::POPUP_MENU
) )
325 else if ( nType
== WindowType::STATUSBAR
)
327 return new VCLXAccessibleStatusBar(_pXWindow
);
330 else if ( nType
== WindowType::TABCONTROL
)
332 return new VCLXAccessibleTabControl(_pXWindow
);
335 else if ( nType
== WindowType::TABPAGE
&& pWindow
->GetAccessibleParentWindow() && pWindow
->GetAccessibleParentWindow()->GetType() == WindowType::TABCONTROL
)
337 return new VCLXAccessibleTabPageWindow(_pXWindow
);
340 else if ( nType
== WindowType::FLOATINGWINDOW
)
342 return new FloatingWindowAccessible(_pXWindow
);
345 else if ( nType
== WindowType::BORDERWINDOW
&& hasFloatingChild( pWindow
) )
347 return new FloatingWindowAccessible(_pXWindow
);
350 else if ( ( nType
== WindowType::HELPTEXTWINDOW
) || ( nType
== WindowType::FIXEDLINE
) )
352 return new VCLXAccessibleFixedText(_pXWindow
);
356 return new VCLXAccessibleComponent(_pXWindow
);
362 Reference
< XAccessibleContext
> AccessibleFactory::createAccessibleContext( VCLXToolBox
* _pXWindow
)
364 return new VCLXAccessibleToolBox( _pXWindow
);
367 Reference
< XAccessibleContext
> AccessibleFactory::createAccessibleContext( VCLXHeaderBar
* _pXWindow
)
369 return new VCLXAccessibleHeaderBar(_pXWindow
);
372 Reference
< XAccessibleContext
> AccessibleFactory::createAccessibleContext( SVTXNumericField
* _pXWindow
)
374 return new SVTXAccessibleNumericField( _pXWindow
);
377 vcl::IAccessibleTabListBox
* AccessibleFactory::createAccessibleTabListBox(
378 const Reference
< XAccessible
>& rxParent
, SvHeaderTabListBox
& rBox
) const
380 return new AccessibleTabListBox( rxParent
, rBox
);
383 rtl::Reference
<vcl::IAccessibleBrowseBox
> AccessibleFactory::createAccessibleBrowseBox(
384 const Reference
< XAccessible
>& _rxParent
, vcl::IAccessibleTableProvider
& _rBrowseBox
) const
386 return new AccessibleBrowseBoxAccess( _rxParent
, _rBrowseBox
);
389 rtl::Reference
<IAccessibleTableControl
> AccessibleFactory::createAccessibleTableControl(
390 const Reference
< XAccessible
>& _rxParent
, IAccessibleTable
& _rTable
) const
392 return new AccessibleGridControlAccess( _rxParent
, _rTable
);
395 Reference
< XAccessible
> AccessibleFactory::createAccessibleIconChoiceCtrl(
396 SvtIconChoiceCtrl
& _rIconCtrl
, const Reference
< XAccessible
>& _xParent
) const
398 return new AccessibleIconChoiceCtrl( _rIconCtrl
, _xParent
);
401 Reference
< XAccessible
> AccessibleFactory::createAccessibleTabBar( TabBar
& _rTabBar
) const
403 #if HAVE_FEATURE_SCRIPTING
404 return new AccessibleTabBar( &_rTabBar
);
411 Reference
< XAccessibleContext
> AccessibleFactory::createAccessibleTextWindowContext(
412 VCLXWindow
* pVclXWindow
, TextEngine
& rEngine
, TextView
& rView
) const
414 return new Document( pVclXWindow
, rEngine
, rView
);
417 Reference
< XAccessible
> AccessibleFactory::createAccessibleTreeListBox(
418 SvTreeListBox
& _rListBox
, const Reference
< XAccessible
>& _xParent
) const
420 return new AccessibleListBox( _rListBox
, _xParent
);
423 Reference
< XAccessible
> AccessibleFactory::createAccessibleIconView(
424 SvTreeListBox
& _rListBox
, const Reference
< XAccessible
>& _xParent
) const
426 return new AccessibleIconView( _rListBox
, _xParent
);
429 Reference
< XAccessible
> AccessibleFactory::createAccessibleBrowseBoxHeaderBar(
430 const Reference
< XAccessible
>& rxParent
, vcl::IAccessibleTableProvider
& _rOwningTable
,
431 AccessibleBrowseBoxObjType _eObjType
) const
433 return new AccessibleBrowseBoxHeaderBar( rxParent
, _rOwningTable
, _eObjType
);
436 Reference
< XAccessible
> AccessibleFactory::createAccessibleBrowseBoxTableCell(
437 const Reference
< XAccessible
>& _rxParent
, vcl::IAccessibleTableProvider
& _rBrowseBox
,
438 const Reference
< XWindow
>& _xFocusWindow
, sal_Int32 _nRowId
, sal_uInt16 _nColId
, sal_Int32 _nOffset
) const
440 return new AccessibleBrowseBoxTableCell( _rxParent
, _rBrowseBox
, _xFocusWindow
,
441 _nRowId
, _nColId
, _nOffset
);
444 Reference
< XAccessible
> AccessibleFactory::createAccessibleBrowseBoxHeaderCell(
445 sal_Int32 _nColumnRowId
, const Reference
< XAccessible
>& rxParent
, vcl::IAccessibleTableProvider
& _rBrowseBox
,
446 const Reference
< XWindow
>& _xFocusWindow
, AccessibleBrowseBoxObjType _eObjType
) const
448 return new AccessibleBrowseBoxHeaderCell( _nColumnRowId
, rxParent
, _rBrowseBox
,
449 _xFocusWindow
, _eObjType
);
452 Reference
< XAccessible
> AccessibleFactory::createAccessibleCheckBoxCell(
453 const Reference
< XAccessible
>& _rxParent
, vcl::IAccessibleTableProvider
& _rBrowseBox
,
454 const Reference
< XWindow
>& _xFocusWindow
, sal_Int32 _nRowPos
, sal_uInt16 _nColPos
,
455 const TriState
& _eState
, bool _bIsTriState
) const
457 return new AccessibleCheckBoxCell( _rxParent
, _rBrowseBox
, _xFocusWindow
,
458 _nRowPos
, _nColPos
, _eState
, _bIsTriState
);
461 Reference
< XAccessible
> AccessibleFactory::createEditBrowseBoxTableCellAccess(
462 const Reference
< XAccessible
>& _rxParent
, const Reference
< XAccessible
>& _rxControlAccessible
,
463 const Reference
< XWindow
>& _rxFocusWindow
, vcl::IAccessibleTableProvider
& _rBrowseBox
,
464 sal_Int32 _nRowPos
, sal_uInt16 _nColPos
) const
466 return new EditBrowseBoxTableCellAccess( _rxParent
, _rxControlAccessible
,
467 _rxFocusWindow
, _rBrowseBox
, _nRowPos
, _nColPos
);
470 } // anonymous namespace
472 #if HAVE_FEATURE_DESKTOP
474 /// anonymous implementation namespace
477 class GetStandardAccessibleFactoryService
:
478 public ::cppu::WeakImplHelper
<
479 css::lang::XServiceInfo
,
480 css::lang::XUnoTunnel
>
483 // css::lang::XServiceInfo:
484 virtual OUString SAL_CALL
getImplementationName() override
485 { return u
"com.sun.star.accessibility.comp.GetStandardAccessibleFactoryService"_ustr
; }
486 virtual sal_Bool SAL_CALL
supportsService(const OUString
& serviceName
) override
487 { return cppu::supportsService(this, serviceName
); }
488 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
489 { return { u
"com.sun.star.accessibility.GetStandardAccessibleFactoryService"_ustr
}; }
492 virtual sal_Int64 SAL_CALL
getSomething( const ::css::uno::Sequence
< ::sal_Int8
>& /*aIdentifier*/ ) override
494 ::toolkit::IAccessibleFactory
* pFactory
= new AccessibleFactory
;
496 return reinterpret_cast<sal_Int64
>(pFactory
);
500 } // closing anonymous implementation namespace
502 /* this is the entry point to retrieve a factory for the toolkit-level Accessible/Contexts supplied
505 This function implements the factory function needed in toolkit
506 (of type GetStandardAccComponentFactory).
510 SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
511 com_sun_star_accessibility_GetStandardAccessibleFactoryService_get_implementation(
512 css::uno::XComponentContext
*,
513 css::uno::Sequence
<css::uno::Any
> const &)
515 return cppu::acquire(new GetStandardAccessibleFactoryService
);
519 /** this is the entry point to retrieve a factory for the svtools-level Accessible/Contexts supplied
522 This function implements the factory function needed in svtools
523 (of type GetSvtAccessibilityComponentFactory).
527 SAL_DLLPUBLIC_EXPORT
void* getSvtAccessibilityComponentFactory()
529 ::vcl::IAccessibleFactory
* pFactory
= new AccessibleFactory
;
534 #endif // HAVE_FEATURE_DESKTOP
536 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */