1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: acc_factory.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_accessibility.hxx"
33 #include <accessibility/helper/acc_factory.hxx>
35 #ifndef _TOOLKIT_AWT_VCLXWINDOWS_HXX
36 #include <toolkit/awt/vclxwindows.hxx>
38 #include <accessibility/standard/vclxaccessiblebutton.hxx>
39 #include <accessibility/standard/vclxaccessiblecheckbox.hxx>
40 #ifndef ACCESSIBILITY_STANDARD_VCLXACCESSIBLEDROPDOWCOMBOBOX_HXX
41 #include <accessibility/standard/vclxaccessibledropdowncombobox.hxx>
43 #include <accessibility/standard/vclxaccessiblecombobox.hxx>
44 #ifndef ACCESSIBILITY_STANDARD_VCLXACCESSIBLEDROPDOWLISTBOX_HXX
45 #include <accessibility/standard/vclxaccessibledropdownlistbox.hxx>
47 #include <accessibility/standard/vclxaccessibleedit.hxx>
48 #include <accessibility/standard/vclxaccessiblefixedhyperlink.hxx>
49 #include <accessibility/standard/vclxaccessiblefixedtext.hxx>
50 #include <accessibility/standard/vclxaccessiblelistbox.hxx>
51 #include <accessibility/standard/vclxaccessiblemenu.hxx>
52 #include <accessibility/standard/vclxaccessibleradiobutton.hxx>
53 #include <accessibility/standard/vclxaccessiblescrollbar.hxx>
54 #include <accessibility/standard/vclxaccessibletextcomponent.hxx>
55 #include <accessibility/standard/vclxaccessibletoolbox.hxx>
56 #include <toolkit/awt/vclxaccessiblecomponent.hxx>
57 #include <accessibility/standard/vclxaccessiblestatusbar.hxx>
58 #include <accessibility/standard/vclxaccessibletabcontrol.hxx>
59 #include <accessibility/standard/vclxaccessibletabpagewindow.hxx>
60 #include <accessibility/standard/vclxaccessiblemenubar.hxx>
61 #include <accessibility/standard/vclxaccessiblepopupmenu.hxx>
62 #include <accessibility/extended/accessibletablistbox.hxx>
63 #include <accessibility/extended/AccessibleBrowseBox.hxx>
64 #include <accessibility/extended/accessibleiconchoicectrl.hxx>
65 #include <accessibility/extended/accessibletabbar.hxx>
66 #include <accessibility/extended/accessiblelistbox.hxx>
67 #include <accessibility/extended/AccessibleBrowseBoxHeaderBar.hxx>
68 #include <accessibility/extended/textwindowaccessibility.hxx>
69 #include <accessibility/extended/AccessibleBrowseBoxTableCell.hxx>
70 #include <accessibility/extended/AccessibleBrowseBoxHeaderCell.hxx>
71 #include <accessibility/extended/AccessibleBrowseBoxCheckBoxCell.hxx>
72 #include <accessibility/extended/accessibleeditbrowseboxcell.hxx>
73 #include <vcl/lstbox.hxx>
74 #include <vcl/combobox.hxx>
75 #include "vcl/popupmenuwindow.hxx"
77 #include <floatingwindowaccessible.hxx>
79 //........................................................................
80 namespace accessibility
83 inline bool hasFloatingChild(Window
*pWindow
)
85 Window
* pChild
= pWindow
->GetAccessibleChildWindow(0);
86 if( pChild
&& WINDOW_FLOATINGWINDOW
== pChild
->GetType() )
92 //........................................................................
94 using namespace ::com::sun::star::uno
;
95 using namespace ::com::sun::star::awt
;
96 using namespace ::com::sun::star::accessibility
;
97 using namespace ::svt
;
99 //================================================================
100 //= IAccessibleFactory
101 //================================================================
102 class AccessibleFactory
:public ::toolkit::IAccessibleFactory
103 ,public ::svt::IAccessibleFactory
106 oslInterlockedCount m_refCount
;
112 virtual oslInterlockedCount SAL_CALL
acquire();
113 virtual oslInterlockedCount SAL_CALL
release();
115 // ::toolkit::IAccessibleFactory
116 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleContext
>
117 createAccessibleContext( VCLXButton
* _pXWindow
);
118 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleContext
>
119 createAccessibleContext( VCLXCheckBox
* _pXWindow
);
120 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleContext
>
121 createAccessibleContext( VCLXRadioButton
* _pXWindow
);
122 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleContext
>
123 createAccessibleContext( VCLXListBox
* _pXWindow
);
124 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleContext
>
125 createAccessibleContext( VCLXFixedText
* _pXWindow
);
126 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleContext
>
127 createAccessibleContext( VCLXFixedHyperlink
* _pXWindow
);
128 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleContext
>
129 createAccessibleContext( VCLXScrollBar
* _pXWindow
);
130 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleContext
>
131 createAccessibleContext( VCLXEdit
* _pXWindow
);
132 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleContext
>
133 createAccessibleContext( VCLXComboBox
* _pXWindow
);
134 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleContext
>
135 createAccessibleContext( VCLXToolBox
* _pXWindow
);
136 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleContext
>
137 createAccessibleContext( VCLXWindow
* _pXWindow
);
138 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
>
139 createAccessible( Menu
* _pMenu
, sal_Bool _bIsMenuBar
);
141 // ::svt::IAccessibleFactory
142 virtual IAccessibleTabListBox
*
143 createAccessibleTabListBox(
144 const ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
>& rxParent
,
145 SvHeaderTabListBox
& rBox
148 virtual IAccessibleBrowseBox
*
149 createAccessibleBrowseBox(
150 const ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
>& _rxParent
,
151 IAccessibleTableProvider
& _rBrowseBox
154 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
>
155 createAccessibleIconChoiceCtrl(
156 SvtIconChoiceCtrl
& _rIconCtrl
,
157 const ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
>& _xParent
160 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
>
161 createAccessibleTabBar(
165 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleContext
>
166 createAccessibleTextWindowContext(
167 VCLXWindow
* pVclXWindow
, TextEngine
& rEngine
, TextView
& rView
, bool bCompoundControlChild
170 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
>
171 createAccessibleTreeListBox(
172 SvTreeListBox
& _rListBox
,
173 const ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
>& _xParent
176 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
>
177 createAccessibleBrowseBoxHeaderBar(
178 const ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
>& rxParent
,
179 IAccessibleTableProvider
& _rOwningTable
,
180 AccessibleBrowseBoxObjType _eObjType
183 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
>
184 createAccessibleBrowseBoxTableCell(
185 const ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
>& _rxParent
,
186 IAccessibleTableProvider
& _rBrowseBox
,
187 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
>& _xFocusWindow
,
193 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
>
194 createAccessibleBrowseBoxHeaderCell(
195 sal_Int32 _nColumnRowId
,
196 const ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
>& rxParent
,
197 IAccessibleTableProvider
& _rBrowseBox
,
198 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
>& _xFocusWindow
,
199 AccessibleBrowseBoxObjType _eObjType
202 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
>
203 createAccessibleCheckBoxCell(
204 const ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
>& _rxParent
,
205 IAccessibleTableProvider
& _rBrowseBox
,
206 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
>& _xFocusWindow
,
209 const TriState
& _eState
,
211 sal_Bool _bIsTriState
214 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
>
215 createEditBrowseBoxTableCellAccess(
216 const ::com::sun::star::uno::Reference
< com::sun::star::accessibility::XAccessible
>& _rxParent
,
217 const ::com::sun::star::uno::Reference
< com::sun::star::accessibility::XAccessible
>& _rxControlAccessible
,
218 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
>& _rxFocusWindow
,
219 IAccessibleTableProvider
& _rBrowseBox
,
225 virtual ~AccessibleFactory();
229 //--------------------------------------------------------------------
230 AccessibleFactory::AccessibleFactory()
235 //--------------------------------------------------------------------
236 AccessibleFactory::~AccessibleFactory()
240 //--------------------------------------------------------------------
241 oslInterlockedCount SAL_CALL
AccessibleFactory::acquire()
243 return osl_incrementInterlockedCount( &m_refCount
);
246 //--------------------------------------------------------------------
247 oslInterlockedCount SAL_CALL
AccessibleFactory::release()
249 if ( 0 == osl_decrementInterlockedCount( &m_refCount
) )
257 //--------------------------------------------------------------------
258 Reference
< XAccessible
> AccessibleFactory::createAccessible( Menu
* _pMenu
, sal_Bool _bIsMenuBar
)
260 OAccessibleMenuBaseComponent
* pAccessible
;
262 pAccessible
= new VCLXAccessibleMenuBar( _pMenu
);
264 pAccessible
= new VCLXAccessiblePopupMenu( _pMenu
);
265 pAccessible
->SetStates();
269 //--------------------------------------------------------------------
270 Reference
< XAccessibleContext
> AccessibleFactory::createAccessibleContext( VCLXButton
* _pXWindow
)
272 return new VCLXAccessibleButton( _pXWindow
);
275 //--------------------------------------------------------------------
276 Reference
< XAccessibleContext
> AccessibleFactory::createAccessibleContext( VCLXCheckBox
* _pXWindow
)
278 return new VCLXAccessibleCheckBox( _pXWindow
);
281 //--------------------------------------------------------------------
282 Reference
< XAccessibleContext
> AccessibleFactory::createAccessibleContext( VCLXRadioButton
* _pXWindow
)
284 return new VCLXAccessibleRadioButton( _pXWindow
);
287 //--------------------------------------------------------------------
288 Reference
< XAccessibleContext
> AccessibleFactory::createAccessibleContext( VCLXListBox
* _pXWindow
)
290 sal_Bool bIsDropDownBox
= sal_False
;
291 ListBox
* pBox
= static_cast< ListBox
* >( _pXWindow
->GetWindow() );
293 bIsDropDownBox
= ( ( pBox
->GetStyle() & WB_DROPDOWN
) == WB_DROPDOWN
);
295 if ( bIsDropDownBox
)
296 return new VCLXAccessibleDropDownListBox( _pXWindow
);
298 return new VCLXAccessibleListBox( _pXWindow
);
301 //--------------------------------------------------------------------
302 Reference
< XAccessibleContext
> AccessibleFactory::createAccessibleContext( VCLXFixedText
* _pXWindow
)
304 return new VCLXAccessibleFixedText( _pXWindow
);
307 //--------------------------------------------------------------------
308 Reference
< XAccessibleContext
> AccessibleFactory::createAccessibleContext( VCLXFixedHyperlink
* _pXWindow
)
310 return new VCLXAccessibleFixedHyperlink( _pXWindow
);
313 //--------------------------------------------------------------------
314 Reference
< XAccessibleContext
> AccessibleFactory::createAccessibleContext( VCLXScrollBar
* _pXWindow
)
316 return new VCLXAccessibleScrollBar( _pXWindow
);
319 //--------------------------------------------------------------------
320 Reference
< XAccessibleContext
> AccessibleFactory::createAccessibleContext( VCLXEdit
* _pXWindow
)
322 return new VCLXAccessibleEdit( _pXWindow
);
325 //--------------------------------------------------------------------
326 Reference
< XAccessibleContext
> AccessibleFactory::createAccessibleContext( VCLXComboBox
* _pXWindow
)
328 sal_Bool bIsDropDownBox
= sal_False
;
329 ComboBox
* pBox
= static_cast< ComboBox
* >( _pXWindow
->GetWindow() );
331 bIsDropDownBox
= ( ( pBox
->GetStyle() & WB_DROPDOWN
) == WB_DROPDOWN
);
333 if ( bIsDropDownBox
)
334 return new VCLXAccessibleDropDownComboBox( _pXWindow
);
336 return new VCLXAccessibleComboBox( _pXWindow
);
339 //--------------------------------------------------------------------
340 Reference
< XAccessibleContext
> AccessibleFactory::createAccessibleContext( VCLXWindow
* _pXWindow
)
342 Reference
< XAccessibleContext
> xContext
;
344 Window
* pWindow
= _pXWindow
->GetWindow();
347 WindowType nType
= pWindow
->GetType();
349 if ( nType
== WINDOW_MENUBARWINDOW
|| pWindow
->IsMenuFloatingWindow() || pWindow
->IsToolbarFloatingWindow() )
351 Reference
< XAccessible
> xAcc( pWindow
->GetAccessible() );
354 Reference
< XAccessibleContext
> xCont( xAcc
->getAccessibleContext() );
355 if ( pWindow
->GetType() == WINDOW_MENUBARWINDOW
||
356 ( xCont
.is() && xCont
->getAccessibleRole() == AccessibleRole::POPUP_MENU
) )
362 else if ( nType
== WINDOW_STATUSBAR
)
364 xContext
= (XAccessibleContext
*) new VCLXAccessibleStatusBar( _pXWindow
);
366 else if ( nType
== WINDOW_TABCONTROL
)
368 xContext
= (XAccessibleContext
*) new VCLXAccessibleTabControl( _pXWindow
);
370 else if ( nType
== WINDOW_TABPAGE
&& pWindow
->GetAccessibleParentWindow() && pWindow
->GetAccessibleParentWindow()->GetType() == WINDOW_TABCONTROL
)
372 xContext
= new VCLXAccessibleTabPageWindow( _pXWindow
);
374 else if ( nType
== WINDOW_FLOATINGWINDOW
)
376 xContext
= new FloatingWindowAccessible( _pXWindow
);
378 else if ( nType
== WINDOW_BORDERWINDOW
&& hasFloatingChild( pWindow
) )
380 PopupMenuFloatingWindow
* pChild
= dynamic_cast<PopupMenuFloatingWindow
*>(
381 pWindow
->GetAccessibleChildWindow(0));
382 if ( pChild
&& pChild
->IsPopupMenu() )
384 // Get the accessible context from the child window.
385 Reference
<XAccessible
> xAccessible
= pChild
->CreateAccessible();
386 if (xAccessible
.is())
387 xContext
= xAccessible
->getAccessibleContext();
390 xContext
= new FloatingWindowAccessible( _pXWindow
);
392 else if ( nType
== WINDOW_HELPTEXTWINDOW
)
394 xContext
= (accessibility::XAccessibleContext
*) new VCLXAccessibleFixedText( _pXWindow
);
398 xContext
= (accessibility::XAccessibleContext
*) new VCLXAccessibleComponent( _pXWindow
);
405 //--------------------------------------------------------------------
406 Reference
< XAccessibleContext
> AccessibleFactory::createAccessibleContext( VCLXToolBox
* _pXWindow
)
408 return new VCLXAccessibleToolBox( _pXWindow
);
411 //--------------------------------------------------------------------
412 IAccessibleTabListBox
* AccessibleFactory::createAccessibleTabListBox(
413 const Reference
< XAccessible
>& rxParent
, SvHeaderTabListBox
& rBox
) const
415 return new AccessibleTabListBox( rxParent
, rBox
);
418 //--------------------------------------------------------------------
419 IAccessibleBrowseBox
* AccessibleFactory::createAccessibleBrowseBox(
420 const Reference
< XAccessible
>& _rxParent
, IAccessibleTableProvider
& _rBrowseBox
) const
422 return new AccessibleBrowseBoxAccess( _rxParent
, _rBrowseBox
);
425 //--------------------------------------------------------------------
426 Reference
< XAccessible
> AccessibleFactory::createAccessibleIconChoiceCtrl(
427 SvtIconChoiceCtrl
& _rIconCtrl
, const Reference
< XAccessible
>& _xParent
) const
429 return new AccessibleIconChoiceCtrl( _rIconCtrl
, _xParent
);
432 //--------------------------------------------------------------------
433 Reference
< XAccessible
> AccessibleFactory::createAccessibleTabBar( TabBar
& _rTabBar
) const
435 return new AccessibleTabBar( &_rTabBar
);
438 //--------------------------------------------------------------------
439 Reference
< XAccessibleContext
> AccessibleFactory::createAccessibleTextWindowContext(
440 VCLXWindow
* pVclXWindow
, TextEngine
& rEngine
, TextView
& rView
, bool bCompoundControlChild
) const
442 return new Document( pVclXWindow
, rEngine
, rView
, bCompoundControlChild
);
445 //--------------------------------------------------------------------
446 Reference
< XAccessible
> AccessibleFactory::createAccessibleTreeListBox(
447 SvTreeListBox
& _rListBox
, const Reference
< XAccessible
>& _xParent
) const
449 return new AccessibleListBox( _rListBox
, _xParent
);
452 //--------------------------------------------------------------------
453 Reference
< XAccessible
> AccessibleFactory::createAccessibleBrowseBoxHeaderBar(
454 const Reference
< XAccessible
>& rxParent
, IAccessibleTableProvider
& _rOwningTable
,
455 AccessibleBrowseBoxObjType _eObjType
) const
457 return new AccessibleBrowseBoxHeaderBar( rxParent
, _rOwningTable
, _eObjType
);
460 //--------------------------------------------------------------------
461 Reference
< XAccessible
> AccessibleFactory::createAccessibleBrowseBoxTableCell(
462 const Reference
< XAccessible
>& _rxParent
, IAccessibleTableProvider
& _rBrowseBox
,
463 const Reference
< XWindow
>& _xFocusWindow
, sal_Int32 _nRowId
, sal_uInt16 _nColId
, sal_Int32 _nOffset
) const
465 return new AccessibleBrowseBoxTableCell( _rxParent
, _rBrowseBox
, _xFocusWindow
,
466 _nRowId
, _nColId
, _nOffset
);
469 //--------------------------------------------------------------------
470 Reference
< XAccessible
> AccessibleFactory::createAccessibleBrowseBoxHeaderCell(
471 sal_Int32 _nColumnRowId
, const Reference
< XAccessible
>& rxParent
, IAccessibleTableProvider
& _rBrowseBox
,
472 const Reference
< XWindow
>& _xFocusWindow
, AccessibleBrowseBoxObjType _eObjType
) const
474 return new AccessibleBrowseBoxHeaderCell( _nColumnRowId
, rxParent
, _rBrowseBox
,
475 _xFocusWindow
, _eObjType
);
478 //--------------------------------------------------------------------
479 Reference
< XAccessible
> AccessibleFactory::createAccessibleCheckBoxCell(
480 const Reference
< XAccessible
>& _rxParent
, IAccessibleTableProvider
& _rBrowseBox
,
481 const Reference
< XWindow
>& _xFocusWindow
, sal_Int32 _nRowPos
, sal_uInt16 _nColPos
,
482 const TriState
& _eState
, sal_Bool _bEnabled
, sal_Bool _bIsTriState
) const
484 return new AccessibleCheckBoxCell( _rxParent
, _rBrowseBox
, _xFocusWindow
,
485 _nRowPos
, _nColPos
, _eState
, _bEnabled
, _bIsTriState
);
488 //--------------------------------------------------------------------
489 Reference
< XAccessible
> AccessibleFactory::createEditBrowseBoxTableCellAccess(
490 const Reference
< XAccessible
>& _rxParent
, const Reference
< XAccessible
>& _rxControlAccessible
,
491 const Reference
< XWindow
>& _rxFocusWindow
, IAccessibleTableProvider
& _rBrowseBox
,
492 sal_Int32 _nRowPos
, sal_uInt16 _nColPos
) const
494 return new EditBrowseBoxTableCellAccess( _rxParent
, _rxControlAccessible
,
495 _rxFocusWindow
, _rBrowseBox
, _nRowPos
, _nColPos
);
498 //........................................................................
499 } // namespace accessibility
500 //........................................................................
502 //========================================================================
503 extern "C" void* SAL_CALL
getStandardAccessibleFactory()
505 ::toolkit::IAccessibleFactory
* pFactory
= new ::accessibility::AccessibleFactory
;
510 extern "C" void* SAL_CALL
getSvtAccessibilityComponentFactory()
512 ::svt::IAccessibleFactory
* pFactory
= new ::accessibility::AccessibleFactory
;