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>
24 #include <vcl/accessibletableprovider.hxx>
25 #include <toolkit/helper/convert.hxx>
26 #include <toolkit/helper/vclunohelper.hxx>
27 #include <sal/types.h>
30 namespace accessibility
33 using namespace ::com::sun::star::uno
;
34 using namespace ::com::sun::star
;
35 using namespace ::com::sun::star::lang
;
36 using namespace ::com::sun::star::accessibility
;
38 // Ctor/Dtor/disposing
40 AccessibleBrowseBox::AccessibleBrowseBox(
41 const css::uno::Reference
< css::accessibility::XAccessible
>& _rxParent
, const css::uno::Reference
< css::accessibility::XAccessible
>& _rxCreator
,
42 ::vcl::IAccessibleTableProvider
& _rBrowseBox
)
43 : AccessibleBrowseBoxBase( _rxParent
, _rBrowseBox
,nullptr, AccessibleBrowseBoxObjType::BrowseBox
),
44 m_aCreator(_rxCreator
)
46 m_xFocusWindow
= VCLUnoHelper::GetInterface(mpBrowseBox
->GetWindowInstance());
49 void AccessibleBrowseBox::setCreator( const css::uno::Reference
< css::accessibility::XAccessible
>& _rxCreator
)
51 #if OSL_DEBUG_LEVEL > 0
52 css::uno::Reference
< css::accessibility::XAccessible
> xCreator(m_aCreator
);
53 OSL_ENSURE( !xCreator
.is(), "extended/AccessibleBrowseBox::setCreator: creator already set!" );
55 m_aCreator
= _rxCreator
;
59 AccessibleBrowseBox::~AccessibleBrowseBox()
64 void SAL_CALL
AccessibleBrowseBox::disposing()
66 ::osl::MutexGuard
aGuard( getMutex() );
75 if ( mxRowHeaderBar
.is() )
77 mxRowHeaderBar
->dispose();
78 mxRowHeaderBar
.clear();
80 if ( mxColumnHeaderBar
.is() )
82 mxColumnHeaderBar
->dispose();
83 mxColumnHeaderBar
.clear();
86 AccessibleBrowseBoxBase::disposing();
90 // css::accessibility::XAccessibleContext
92 sal_Int32 SAL_CALL
AccessibleBrowseBox::getAccessibleChildCount()
94 SolarMethodGuard
aGuard(getMutex());
97 return vcl::BBINDEX_FIRSTCONTROL
+ mpBrowseBox
->GetAccessibleControlCount();
101 css::uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
102 AccessibleBrowseBox::getAccessibleChild( sal_Int32 nChildIndex
)
104 SolarMethodGuard
aGuard(getMutex());
107 css::uno::Reference
< css::accessibility::XAccessible
> xRet
;
108 if( nChildIndex
>= 0 )
110 if( nChildIndex
< vcl::BBINDEX_FIRSTCONTROL
)
111 xRet
= implGetFixedChild( nChildIndex
);
114 // additional controls
115 nChildIndex
-= vcl::BBINDEX_FIRSTCONTROL
;
116 if( nChildIndex
< mpBrowseBox
->GetAccessibleControlCount() )
117 xRet
= mpBrowseBox
->CreateAccessibleControl( nChildIndex
);
122 throw lang::IndexOutOfBoundsException();
126 // css::accessibility::XAccessibleComponent
128 css::uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
129 AccessibleBrowseBox::getAccessibleAtPoint( const awt::Point
& rPoint
)
131 SolarMethodGuard
aGuard(getMutex());
134 css::uno::Reference
< css::accessibility::XAccessible
> xChild
;
135 sal_Int32 nIndex
= 0;
136 if( mpBrowseBox
->ConvertPointToControlIndex( nIndex
, VCLPoint( rPoint
) ) )
137 xChild
= mpBrowseBox
->CreateAccessibleControl( nIndex
);
140 // try whether point is in one of the fixed children
141 // (table, header bars, corner control)
142 Point
aPoint( VCLPoint( rPoint
) );
143 for( nIndex
= 0; (nIndex
< vcl::BBINDEX_FIRSTCONTROL
) && !xChild
.is(); ++nIndex
)
145 css::uno::Reference
< css::accessibility::XAccessible
> xCurrChild( implGetFixedChild( nIndex
) );
146 css::uno::Reference
< css::accessibility::XAccessibleComponent
>
147 xCurrChildComp( xCurrChild
, uno::UNO_QUERY
);
149 if( xCurrChildComp
.is() &&
150 VCLRectangle( xCurrChildComp
->getBounds() ).Contains( aPoint
) )
158 void SAL_CALL
AccessibleBrowseBox::grabFocus()
160 SolarMethodGuard
aGuard(getMutex());
163 mpBrowseBox
->GrabFocus();
168 OUString SAL_CALL
AccessibleBrowseBox::getImplementationName()
170 return "com.sun.star.comp.svtools.AccessibleBrowseBox";
174 // internal virtual methods
176 tools::Rectangle
AccessibleBrowseBox::implGetBoundingBox()
178 vcl::Window
* pParent
= mpBrowseBox
->GetAccessibleParentWindow();
179 OSL_ENSURE( pParent
, "implGetBoundingBox - missing parent window" );
180 return mpBrowseBox
->GetWindowExtentsRelative( pParent
);
184 tools::Rectangle
AccessibleBrowseBox::implGetBoundingBoxOnScreen()
186 return mpBrowseBox
->GetWindowExtentsRelative( nullptr );
189 // internal helper methods
190 css::uno::Reference
< css::accessibility::XAccessible
> AccessibleBrowseBox::implGetTable()
194 mxTable
= createAccessibleTable();
200 css::uno::Reference
< css::accessibility::XAccessible
>
201 AccessibleBrowseBox::implGetHeaderBar(AccessibleBrowseBoxObjType eObjType
)
203 css::uno::Reference
< css::accessibility::XAccessible
> xRet
;
204 rtl::Reference
< AccessibleBrowseBoxHeaderBar
>* pxMember
= nullptr;
206 if( eObjType
== AccessibleBrowseBoxObjType::RowHeaderBar
)
207 pxMember
= &mxRowHeaderBar
;
208 else if( eObjType
== AccessibleBrowseBoxObjType::ColumnHeaderBar
)
209 pxMember
= &mxColumnHeaderBar
;
213 if( !pxMember
->is() )
215 rtl::Reference
<AccessibleBrowseBoxHeaderBar
> pHeaderBar
= new AccessibleBrowseBoxHeaderBar(
216 m_aCreator
, *mpBrowseBox
, eObjType
);
217 *pxMember
= pHeaderBar
;
219 xRet
= pxMember
->get();
224 css::uno::Reference
< css::accessibility::XAccessible
>
225 AccessibleBrowseBox::implGetFixedChild( sal_Int32 nChildIndex
)
227 css::uno::Reference
< css::accessibility::XAccessible
> xRet
;
228 switch( nChildIndex
)
230 case vcl::BBINDEX_COLUMNHEADERBAR
:
231 xRet
= implGetHeaderBar( AccessibleBrowseBoxObjType::ColumnHeaderBar
);
233 case vcl::BBINDEX_ROWHEADERBAR
:
234 xRet
= implGetHeaderBar( AccessibleBrowseBoxObjType::RowHeaderBar
);
236 case vcl::BBINDEX_TABLE
:
237 xRet
= implGetTable();
243 rtl::Reference
<AccessibleBrowseBoxTable
> AccessibleBrowseBox::createAccessibleTable()
245 css::uno::Reference
< css::accessibility::XAccessible
> xCreator(m_aCreator
);
246 OSL_ENSURE( xCreator
.is(), "extended/AccessibleBrowseBox::createAccessibleTable: my creator died - how this?" );
247 return new AccessibleBrowseBoxTable( xCreator
, *mpBrowseBox
);
250 void AccessibleBrowseBox::commitTableEvent(sal_Int16 _nEventId
,const Any
& _rNewValue
,const Any
& _rOldValue
)
254 mxTable
->commitEvent(_nEventId
,_rNewValue
,_rOldValue
);
258 void AccessibleBrowseBox::commitHeaderBarEvent( sal_Int16 _nEventId
,
259 const Any
& _rNewValue
,
260 const Any
& _rOldValue
,bool _bColumnHeaderBar
)
262 rtl::Reference
< AccessibleBrowseBoxHeaderBar
>& xHeaderBar
= _bColumnHeaderBar
? mxColumnHeaderBar
: mxRowHeaderBar
;
263 if ( xHeaderBar
.is() )
264 xHeaderBar
->commitEvent(_nEventId
,_rNewValue
,_rOldValue
);
268 // = AccessibleBrowseBoxAccess
270 AccessibleBrowseBoxAccess::AccessibleBrowseBoxAccess( const css::uno::Reference
< css::accessibility::XAccessible
>& _rxParent
, ::vcl::IAccessibleTableProvider
& _rBrowseBox
)
271 :m_xParent( _rxParent
)
272 ,m_rBrowseBox( _rBrowseBox
)
277 AccessibleBrowseBoxAccess::~AccessibleBrowseBoxAccess()
282 void AccessibleBrowseBoxAccess::dispose()
284 ::osl::MutexGuard
aGuard( m_aMutex
);
288 m_xContext
->dispose();
294 css::uno::Reference
< css::accessibility::XAccessibleContext
> SAL_CALL
AccessibleBrowseBoxAccess::getAccessibleContext()
296 ::osl::MutexGuard
aGuard( m_aMutex
);
298 // if the context died meanwhile (there is no listener, so it won't tell us explicitly when this happens),
299 // then reset and re-create.
300 if ( m_xContext
.is() && !m_xContext
->isAlive() )
301 m_xContext
= nullptr;
303 if ( !m_xContext
.is() )
304 m_xContext
= new AccessibleBrowseBox( m_xParent
, this, m_rBrowseBox
);
311 } // namespace accessibility
313 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */