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 <extended/AccessibleBrowseBox.hxx>
21 #include <extended/AccessibleBrowseBoxTable.hxx>
22 #include <extended/AccessibleBrowseBoxHeaderBar.hxx>
23 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
25 #include <vcl/accessibletableprovider.hxx>
26 #include <toolkit/helper/convert.hxx>
27 #include <toolkit/helper/vclunohelper.hxx>
28 #include <sal/types.h>
31 namespace accessibility
34 using namespace ::com::sun::star::uno
;
35 using namespace ::com::sun::star
;
36 using namespace ::com::sun::star::lang
;
37 using namespace ::com::sun::star::accessibility
;
39 // Ctor/Dtor/disposing
41 AccessibleBrowseBox::AccessibleBrowseBox(
42 const css::uno::Reference
< css::accessibility::XAccessible
>& _rxParent
, const css::uno::Reference
< css::accessibility::XAccessible
>& _rxCreator
,
43 ::vcl::IAccessibleTableProvider
& _rBrowseBox
)
44 : AccessibleBrowseBoxBase( _rxParent
, _rBrowseBox
,nullptr, AccessibleBrowseBoxObjType::BrowseBox
),
45 m_aCreator(_rxCreator
)
47 m_xFocusWindow
= VCLUnoHelper::GetInterface(mpBrowseBox
->GetWindowInstance());
50 void AccessibleBrowseBox::setCreator( const css::uno::Reference
< css::accessibility::XAccessible
>& _rxCreator
)
52 #if OSL_DEBUG_LEVEL > 0
53 css::uno::Reference
< css::accessibility::XAccessible
> xCreator(m_aCreator
);
54 OSL_ENSURE( !xCreator
.is(), "extended/AccessibleBrowseBox::setCreator: creator already set!" );
56 m_aCreator
= _rxCreator
;
60 AccessibleBrowseBox::~AccessibleBrowseBox()
65 void SAL_CALL
AccessibleBrowseBox::disposing()
67 ::osl::MutexGuard
aGuard( getMutex() );
76 if ( mxRowHeaderBar
.is() )
78 mxRowHeaderBar
->dispose();
79 mxRowHeaderBar
.clear();
81 if ( mxColumnHeaderBar
.is() )
83 mxColumnHeaderBar
->dispose();
84 mxColumnHeaderBar
.clear();
87 AccessibleBrowseBoxBase::disposing();
91 // css::accessibility::XAccessibleContext
93 sal_Int64 SAL_CALL
AccessibleBrowseBox::getAccessibleChildCount()
95 SolarMethodGuard
aGuard(getMutex());
98 return vcl::BBINDEX_FIRSTCONTROL
+ mpBrowseBox
->GetAccessibleControlCount();
102 css::uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
103 AccessibleBrowseBox::getAccessibleChild( sal_Int64 nChildIndex
)
105 SolarMethodGuard
aGuard(getMutex());
108 if (nChildIndex
< 0 || nChildIndex
>= getAccessibleChildCount())
109 throw lang::IndexOutOfBoundsException();
111 css::uno::Reference
< css::accessibility::XAccessible
> xRet
;
112 if( nChildIndex
>= 0 )
114 if( nChildIndex
< vcl::BBINDEX_FIRSTCONTROL
)
115 xRet
= implGetFixedChild( nChildIndex
);
118 // additional controls
119 nChildIndex
-= vcl::BBINDEX_FIRSTCONTROL
;
120 if( nChildIndex
< mpBrowseBox
->GetAccessibleControlCount() )
121 xRet
= mpBrowseBox
->CreateAccessibleControl( nChildIndex
);
126 throw lang::IndexOutOfBoundsException();
130 // css::accessibility::XAccessibleComponent
132 css::uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
133 AccessibleBrowseBox::getAccessibleAtPoint( const awt::Point
& rPoint
)
135 SolarMethodGuard
aGuard(getMutex());
138 css::uno::Reference
< css::accessibility::XAccessible
> xChild
;
139 sal_Int32 nIndex
= 0;
140 if( mpBrowseBox
->ConvertPointToControlIndex( nIndex
, VCLPoint( rPoint
) ) )
141 xChild
= mpBrowseBox
->CreateAccessibleControl( nIndex
);
144 // try whether point is in one of the fixed children
145 // (table, header bars, corner control)
146 Point
aPoint( VCLPoint( rPoint
) );
147 for( nIndex
= 0; (nIndex
< vcl::BBINDEX_FIRSTCONTROL
) && !xChild
.is(); ++nIndex
)
149 css::uno::Reference
< css::accessibility::XAccessible
> xCurrChild( implGetFixedChild( nIndex
) );
150 css::uno::Reference
< css::accessibility::XAccessibleComponent
>
151 xCurrChildComp( xCurrChild
, uno::UNO_QUERY
);
153 if( xCurrChildComp
.is() &&
154 VCLRectangle( xCurrChildComp
->getBounds() ).Contains( aPoint
) )
162 void SAL_CALL
AccessibleBrowseBox::grabFocus()
164 SolarMethodGuard
aGuard(getMutex());
167 mpBrowseBox
->GrabFocus();
172 OUString SAL_CALL
AccessibleBrowseBox::getImplementationName()
174 return "com.sun.star.comp.svtools.AccessibleBrowseBox";
178 // internal virtual methods
180 tools::Rectangle
AccessibleBrowseBox::implGetBoundingBox()
182 vcl::Window
* pParent
= mpBrowseBox
->GetAccessibleParentWindow();
183 OSL_ENSURE( pParent
, "implGetBoundingBox - missing parent window" );
184 return mpBrowseBox
->GetWindowExtentsRelative( pParent
);
188 tools::Rectangle
AccessibleBrowseBox::implGetBoundingBoxOnScreen()
190 return mpBrowseBox
->GetWindowExtentsRelative( nullptr );
193 // internal helper methods
194 css::uno::Reference
< css::accessibility::XAccessible
> AccessibleBrowseBox::implGetTable()
198 mxTable
= createAccessibleTable();
204 css::uno::Reference
< css::accessibility::XAccessible
>
205 AccessibleBrowseBox::implGetHeaderBar(AccessibleBrowseBoxObjType eObjType
)
207 css::uno::Reference
< css::accessibility::XAccessible
> xRet
;
208 rtl::Reference
< AccessibleBrowseBoxHeaderBar
>* pxMember
= nullptr;
210 if( eObjType
== AccessibleBrowseBoxObjType::RowHeaderBar
)
211 pxMember
= &mxRowHeaderBar
;
212 else if( eObjType
== AccessibleBrowseBoxObjType::ColumnHeaderBar
)
213 pxMember
= &mxColumnHeaderBar
;
217 if( !pxMember
->is() )
219 rtl::Reference
<AccessibleBrowseBoxHeaderBar
> pHeaderBar
= new AccessibleBrowseBoxHeaderBar(
220 m_aCreator
, *mpBrowseBox
, eObjType
);
221 *pxMember
= pHeaderBar
;
223 xRet
= pxMember
->get();
228 css::uno::Reference
< css::accessibility::XAccessible
>
229 AccessibleBrowseBox::implGetFixedChild( sal_Int64 nChildIndex
)
231 css::uno::Reference
< css::accessibility::XAccessible
> xRet
;
232 switch( nChildIndex
)
234 case vcl::BBINDEX_COLUMNHEADERBAR
:
235 xRet
= implGetHeaderBar( AccessibleBrowseBoxObjType::ColumnHeaderBar
);
237 case vcl::BBINDEX_ROWHEADERBAR
:
238 xRet
= implGetHeaderBar( AccessibleBrowseBoxObjType::RowHeaderBar
);
240 case vcl::BBINDEX_TABLE
:
241 xRet
= implGetTable();
247 rtl::Reference
<AccessibleBrowseBoxTable
> AccessibleBrowseBox::createAccessibleTable()
249 css::uno::Reference
< css::accessibility::XAccessible
> xCreator(m_aCreator
);
250 OSL_ENSURE( xCreator
.is(), "extended/AccessibleBrowseBox::createAccessibleTable: my creator died - how this?" );
251 return new AccessibleBrowseBoxTable( xCreator
, *mpBrowseBox
);
254 void AccessibleBrowseBox::commitTableEvent(sal_Int16 _nEventId
,const Any
& _rNewValue
,const Any
& _rOldValue
)
258 mxTable
->commitEvent(_nEventId
,_rNewValue
,_rOldValue
);
262 void AccessibleBrowseBox::commitHeaderBarEvent( sal_Int16 _nEventId
,
263 const Any
& _rNewValue
,
264 const Any
& _rOldValue
,bool _bColumnHeaderBar
)
266 rtl::Reference
< AccessibleBrowseBoxHeaderBar
>& xHeaderBar
= _bColumnHeaderBar
? mxColumnHeaderBar
: mxRowHeaderBar
;
267 if ( xHeaderBar
.is() )
268 xHeaderBar
->commitEvent(_nEventId
,_rNewValue
,_rOldValue
);
272 // = AccessibleBrowseBoxAccess
274 AccessibleBrowseBoxAccess::AccessibleBrowseBoxAccess( css::uno::Reference
< css::accessibility::XAccessible
> _xParent
, ::vcl::IAccessibleTableProvider
& _rBrowseBox
)
275 :m_xParent(std::move( _xParent
))
276 ,m_rBrowseBox( _rBrowseBox
)
281 AccessibleBrowseBoxAccess::~AccessibleBrowseBoxAccess()
286 void AccessibleBrowseBoxAccess::dispose()
288 std::unique_lock
aGuard( m_aMutex
);
292 m_xContext
->dispose();
298 css::uno::Reference
< css::accessibility::XAccessibleContext
> SAL_CALL
AccessibleBrowseBoxAccess::getAccessibleContext()
300 std::unique_lock
aGuard( m_aMutex
);
302 // if the context died meanwhile (there is no listener, so it won't tell us explicitly when this happens),
303 // then reset and re-create.
304 if ( m_xContext
.is() && !m_xContext
->isAlive() )
305 m_xContext
= nullptr;
307 if ( !m_xContext
.is() )
308 m_xContext
= new AccessibleBrowseBox( m_xParent
, this, m_rBrowseBox
);
315 } // namespace accessibility
317 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */