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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
|
/* -*- 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 "accessibility/extended/AccessibleToolPanelDeckTabBar.hxx"
#include "accessibility/extended/AccessibleToolPanelDeckTabBarItem.hxx"
#include "accessibility/helper/accresmgr.hxx"
#include "accessibility/helper/accessiblestrings.hrc"
#include <com/sun/star/accessibility/AccessibleRole.hpp>
#include <com/sun/star/accessibility/AccessibleEventId.hpp>
#include <com/sun/star/accessibility/AccessibleStateType.hpp>
#include <com/sun/star/lang/DisposedException.hpp>
#include <svtools/toolpanel/toolpaneldeck.hxx>
#include <svtools/toolpanel/paneltabbar.hxx>
#include <unotools/accessiblestatesethelper.hxx>
#include <toolkit/awt/vclxwindow.hxx>
#include <toolkit/helper/vclunohelper.hxx>
#include <vcl/svapp.hxx>
#include <vcl/button.hxx>
#include <osl/mutex.hxx>
#include <tools/diagnose_ex.h>
#include <vector>
namespace accessibility
{
using ::com::sun::star::uno::Reference;
using ::com::sun::star::uno::XInterface;
using ::com::sun::star::uno::UNO_QUERY;
using ::com::sun::star::uno::UNO_QUERY_THROW;
using ::com::sun::star::uno::UNO_SET_THROW;
using ::com::sun::star::uno::Exception;
using ::com::sun::star::uno::RuntimeException;
using ::com::sun::star::uno::Any;
using ::com::sun::star::uno::makeAny;
using ::com::sun::star::uno::Sequence;
using ::com::sun::star::uno::Type;
using ::com::sun::star::accessibility::XAccessible;
using ::com::sun::star::lang::DisposedException;
using ::com::sun::star::lang::IndexOutOfBoundsException;
using ::com::sun::star::accessibility::XAccessibleContext;
namespace AccessibleRole = ::com::sun::star::accessibility::AccessibleRole;
namespace AccessibleEventId = ::com::sun::star::accessibility::AccessibleEventId;
namespace AccessibleStateType = ::com::sun::star::accessibility::AccessibleStateType;
typedef ::com::sun::star::awt::Point UnoPoint;
// AccessibleWrapper
typedef ::cppu::WeakImplHelper1< XAccessible > AccessibleWrapper_Base;
class AccessibleWrapper : public AccessibleWrapper_Base
{
public:
AccessibleWrapper( const Reference< XAccessibleContext >& i_rContext )
:m_xContext( i_rContext )
{
}
// XAccessible
virtual Reference< XAccessibleContext > SAL_CALL getAccessibleContext( ) throw (RuntimeException)
{
return m_xContext;
}
private:
const Reference< XAccessibleContext > m_xContext;
};
// AccessibleToolPanelTabBar_Impl
class AccessibleToolPanelTabBar_Impl :public ::boost::noncopyable
,public ::svt::IToolPanelDeckListener
{
public:
AccessibleToolPanelTabBar_Impl(
AccessibleToolPanelTabBar& i_rAntiImpl,
const Reference< XAccessible >& i_rAccessibleParent,
::svt::IToolPanelDeck& i_rPanelDeck,
::svt::PanelTabBar& i_rTabBar
);
virtual ~AccessibleToolPanelTabBar_Impl();
void checkDisposed();
bool isDisposed() const { return m_pPanelDeck == NULL; }
void dispose();
::svt::IToolPanelDeck* getPanelDeck() const { return m_pPanelDeck; }
::svt::PanelTabBar* getTabBar() const { return m_pTabBar; }
const Reference< XAccessible >& getAccessibleParent() const { return m_xAccessibleParent; }
Reference< XAccessible > getAccessiblePanelItem( size_t i_nPosition );
Reference< XAccessible > getOwnAccessible() const;
protected:
// IToolPanelDeckListener
virtual void PanelInserted( const ::svt::PToolPanel& i_pPanel, const size_t i_nPosition );
virtual void PanelRemoved( const size_t i_nPosition );
virtual void ActivePanelChanged( const ::boost::optional< size_t >& i_rOldActive, const ::boost::optional< size_t >& i_rNewActive );
virtual void LayouterChanged( const ::svt::PDeckLayouter& i_rNewLayouter );
virtual void Dying();
DECL_LINK( OnWindowEvent, const VclSimpleEvent* );
private:
AccessibleToolPanelTabBar& m_rAntiImpl;
Reference< XAccessible > m_xAccessibleParent;
::svt::IToolPanelDeck* m_pPanelDeck;
::svt::PanelTabBar* m_pTabBar;
::std::vector< Reference< XAccessible > > m_aChildren;
};
AccessibleToolPanelTabBar_Impl::AccessibleToolPanelTabBar_Impl( AccessibleToolPanelTabBar& i_rAntiImpl,
const Reference< XAccessible >& i_rAccessibleParent, ::svt::IToolPanelDeck& i_rPanelDeck, ::svt::PanelTabBar& i_rTabBar )
:m_rAntiImpl( i_rAntiImpl )
,m_xAccessibleParent( i_rAccessibleParent )
,m_pPanelDeck( &i_rPanelDeck )
,m_pTabBar( &i_rTabBar )
,m_aChildren()
{
m_pPanelDeck->AddListener( *this );
m_aChildren.resize( m_pPanelDeck->GetPanelCount() );
const OUString sAccessibleDescription( TK_RES_STRING( RID_STR_ACC_DESC_PANELDECL_TABBAR ) );
i_rTabBar.SetAccessibleName( sAccessibleDescription );
i_rTabBar.SetAccessibleDescription( sAccessibleDescription );
i_rTabBar.GetScrollButton( true ).AddEventListener( LINK( this, AccessibleToolPanelTabBar_Impl, OnWindowEvent ) );
i_rTabBar.GetScrollButton( false ).AddEventListener( LINK( this, AccessibleToolPanelTabBar_Impl, OnWindowEvent ) );
}
void AccessibleToolPanelTabBar_Impl::checkDisposed()
{
if ( isDisposed() )
throw DisposedException( OUString(), *&m_rAntiImpl );
}
AccessibleToolPanelTabBar_Impl::~AccessibleToolPanelTabBar_Impl()
{
if ( !isDisposed() )
dispose();
}
void AccessibleToolPanelTabBar_Impl::dispose()
{
ENSURE_OR_RETURN_VOID( !isDisposed(), "disposed twice" );
m_pPanelDeck->RemoveListener( *this );
m_pPanelDeck = NULL;
m_pTabBar->GetScrollButton( true ).RemoveEventListener( LINK( this, AccessibleToolPanelTabBar_Impl, OnWindowEvent ) );
m_pTabBar->GetScrollButton( false ).RemoveEventListener( LINK( this, AccessibleToolPanelTabBar_Impl, OnWindowEvent ) );
m_pTabBar = NULL;
m_xAccessibleParent.clear();
}
Reference< XAccessible > AccessibleToolPanelTabBar_Impl::getAccessiblePanelItem( size_t i_nPosition )
{
ENSURE_OR_RETURN( !isDisposed(), "AccessibleToolPanelTabBar_Impl::getAccessiblePanelItem: already disposed!", NULL );
ENSURE_OR_RETURN( i_nPosition < m_aChildren.size(), "AccessibleToolPanelTabBar_Impl::getAccessiblePanelItem: invalid index!", NULL );
Reference< XAccessible >& rAccessibleChild( m_aChildren[ i_nPosition ] );
if ( !rAccessibleChild.is() )
{
::rtl::Reference< AccessibleToolPanelDeckTabBarItem > pAccesibleItemContext( new AccessibleToolPanelDeckTabBarItem(
getOwnAccessible(), *m_pPanelDeck, *m_pTabBar, i_nPosition ) );
rAccessibleChild.set( new AccessibleWrapper( pAccesibleItemContext.get() ) );
pAccesibleItemContext->lateInit( rAccessibleChild );
}
return rAccessibleChild;
}
Reference< XAccessible > AccessibleToolPanelTabBar_Impl::getOwnAccessible() const
{
Reference< XAccessible > xOwnAccessible( static_cast< XAccessible* >( m_rAntiImpl.GetVCLXWindow() ) );
OSL_ENSURE( xOwnAccessible->getAccessibleContext() == Reference< XAccessibleContext >( &m_rAntiImpl ),
"AccessibleToolPanelTabBar_Impl::getOwnAccessible: could not retrieve proper XAccessible for /myself!" );
return xOwnAccessible;
}
void AccessibleToolPanelTabBar_Impl::PanelInserted( const ::svt::PToolPanel& i_pPanel, const size_t i_nPosition )
{
ENSURE_OR_RETURN_VOID( i_nPosition <= m_aChildren.size(), "AccessibleToolPanelTabBar_Impl::PanelInserted: illegal position (or invalid cache!)" );
(void)i_pPanel;
m_aChildren.insert( m_aChildren.begin() + i_nPosition, (Reference< XAccessible >)NULL );
m_rAntiImpl.NotifyAccessibleEvent( AccessibleEventId::CHILD, Any(), makeAny( getAccessiblePanelItem( i_nPosition ) ) );
}
void AccessibleToolPanelTabBar_Impl::PanelRemoved( const size_t i_nPosition )
{
ENSURE_OR_RETURN_VOID( i_nPosition < m_aChildren.size(), "AccessibleToolPanelTabBar_Impl::PanelInserted: illegal position (or invalid cache!)" );
const Reference< XAccessible > xOldChild( getAccessiblePanelItem( i_nPosition ) );
m_aChildren.erase( m_aChildren.begin() + i_nPosition );
m_rAntiImpl.NotifyAccessibleEvent( AccessibleEventId::CHILD, makeAny( xOldChild ), Any() );
}
void AccessibleToolPanelTabBar_Impl::ActivePanelChanged( const ::boost::optional< size_t >& i_rOldActive, const ::boost::optional< size_t >& i_rNewActive )
{
(void)i_rOldActive;
(void)i_rNewActive;
}
void AccessibleToolPanelTabBar_Impl::LayouterChanged( const ::svt::PDeckLayouter& i_rNewLayouter )
{
(void)i_rNewLayouter;
m_rAntiImpl.dispose();
}
void AccessibleToolPanelTabBar_Impl::Dying()
{
m_rAntiImpl.dispose();
}
IMPL_LINK( AccessibleToolPanelTabBar_Impl, OnWindowEvent, const VclSimpleEvent*, i_pEvent )
{
ENSURE_OR_RETURN( !isDisposed(), "AccessibleToolPanelTabBar_Impl::OnWindowEvent: already disposed!", 0L );
const VclWindowEvent* pWindowEvent( dynamic_cast< const VclWindowEvent* >( i_pEvent ) );
if ( !pWindowEvent )
return 0L;
const bool bForwardButton = ( pWindowEvent->GetWindow() == &m_pTabBar->GetScrollButton( true ) );
const bool bBackwardButton = ( pWindowEvent->GetWindow() == &m_pTabBar->GetScrollButton( false ) );
ENSURE_OR_RETURN( bForwardButton || bBackwardButton, "AccessibleToolPanelTabBar_Impl::OnWindowEvent: where does this come from?", 0L );
const bool bShow = ( i_pEvent->GetId() == VCLEVENT_WINDOW_SHOW );
const bool bHide = ( i_pEvent->GetId() == VCLEVENT_WINDOW_HIDE );
if ( !bShow && !bHide )
// not interested in events other than visibility changes
return 0L;
const Reference< XAccessible > xButtonAccessible( m_pTabBar->GetScrollButton( bForwardButton ).GetAccessible() );
const Any aOldChild( bHide ? xButtonAccessible : Reference< XAccessible >() );
const Any aNewChild( bShow ? xButtonAccessible : Reference< XAccessible >() );
m_rAntiImpl.NotifyAccessibleEvent( AccessibleEventId::CHILD, aOldChild, aNewChild );
return 1L;
}
// MethodGuard
namespace
{
class MethodGuard
{
public:
MethodGuard( AccessibleToolPanelTabBar_Impl& i_rImpl )
:m_aGuard()
{
i_rImpl.checkDisposed();
}
~MethodGuard()
{
}
private:
SolarMutexGuard m_aGuard;
};
}
// AccessibleToolPanelTabBar
AccessibleToolPanelTabBar::AccessibleToolPanelTabBar( const Reference< XAccessible >& i_rAccessibleParent,
::svt::IToolPanelDeck& i_rPanelDeck, ::svt::PanelTabBar& i_rTabBar )
:AccessibleToolPanelTabBar_Base( i_rTabBar.GetWindowPeer() )
,m_pImpl( new AccessibleToolPanelTabBar_Impl( *this, i_rAccessibleParent, i_rPanelDeck, i_rTabBar ) )
{
}
AccessibleToolPanelTabBar::~AccessibleToolPanelTabBar()
{
}
sal_Int32 SAL_CALL AccessibleToolPanelTabBar::getAccessibleChildCount( ) throw (RuntimeException)
{
MethodGuard aGuard( *m_pImpl );
const bool bHasScrollBack = m_pImpl->getTabBar()->GetScrollButton( false ).IsVisible();
const bool bHasScrollForward = m_pImpl->getTabBar()->GetScrollButton( true ).IsVisible();
return m_pImpl->getPanelDeck()->GetPanelCount()
+ ( bHasScrollBack ? 1 : 0 )
+ ( bHasScrollForward ? 1 : 0 );
}
Reference< XAccessible > SAL_CALL AccessibleToolPanelTabBar::getAccessibleChild( sal_Int32 i_nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
{
MethodGuard aGuard( *m_pImpl );
const bool bHasScrollBack = m_pImpl->getTabBar()->GetScrollButton( false ).IsVisible();
const bool bHasScrollForward = m_pImpl->getTabBar()->GetScrollButton( true ).IsVisible();
const bool bScrollBackRequested = ( bHasScrollBack && ( i_nIndex == 0 ) );
const bool bScrollForwardRequested = ( bHasScrollForward && ( i_nIndex == getAccessibleChildCount() - 1 ) );
OSL_ENSURE( !( bScrollBackRequested && bScrollForwardRequested ), "AccessibleToolPanelTabBar::getAccessibleChild: ouch!" );
if ( bScrollBackRequested || bScrollForwardRequested )
{
Reference< XAccessible > xScrollButtonAccessible( m_pImpl->getTabBar()->GetScrollButton( bScrollForwardRequested ).GetAccessible() );
ENSURE_OR_RETURN( xScrollButtonAccessible.is(), "AccessibleToolPanelTabBar::getAccessibleChild: invalid button accessible!", NULL );
#if OSL_DEBUG_LEVEL > 0
Reference< XAccessibleContext > xScrollButtonContext( xScrollButtonAccessible->getAccessibleContext() );
ENSURE_OR_RETURN( xScrollButtonContext.is(), "AccessibleToolPanelTabBar::getAccessibleChild: invalid button accessible context!", xScrollButtonAccessible );
OSL_ENSURE( xScrollButtonContext->getAccessibleParent() == m_pImpl->getOwnAccessible(),
"AccessibleToolPanelTabBar::getAccessibleChild: wrong parent at the button's accesible!" );
#endif
return xScrollButtonAccessible;
}
return m_pImpl->getAccessiblePanelItem( i_nIndex - ( bHasScrollBack ? 1 : 0 ) );
}
Reference< XAccessible > SAL_CALL AccessibleToolPanelTabBar::getAccessibleParent( ) throw (RuntimeException)
{
MethodGuard aGuard( *m_pImpl );
return m_pImpl->getAccessibleParent();
}
sal_Int16 SAL_CALL AccessibleToolPanelTabBar::getAccessibleRole( ) throw (RuntimeException)
{
MethodGuard aGuard( *m_pImpl );
return AccessibleRole::PAGE_TAB_LIST;
}
namespace
{
bool lcl_covers( const ::Window& i_rWindow, const ::Point& i_rPoint )
{
const Rectangle aWindowBounds( i_rWindow.GetWindowExtentsRelative( i_rWindow.GetParent() ) );
return aWindowBounds.IsInside( i_rPoint );
}
}
Reference< XAccessible > SAL_CALL AccessibleToolPanelTabBar::getAccessibleAtPoint( const UnoPoint& i_rPoint ) throw (RuntimeException)
{
MethodGuard aGuard( *m_pImpl );
// check the tab items
const UnoPoint aOwnScreenPos( getLocationOnScreen() );
const ::Point aRequestedScreenPoint( i_rPoint.X + aOwnScreenPos.X, i_rPoint.Y + aOwnScreenPos.Y );
for ( size_t i=0; i<m_pImpl->getPanelDeck()->GetPanelCount(); ++i )
{
const ::Rectangle aItemScreenRect( m_pImpl->getTabBar()->GetItemScreenRect(i) );
if ( aItemScreenRect.IsInside( aRequestedScreenPoint ) )
return m_pImpl->getAccessiblePanelItem(i);
}
// check the scroll buttons
const ::Point aRequestedClientPoint( VCLUnoHelper::ConvertToVCLPoint( i_rPoint ) );
const bool bHasScrollBack = m_pImpl->getTabBar()->GetScrollButton( false ).IsVisible();
if ( bHasScrollBack && lcl_covers( m_pImpl->getTabBar()->GetScrollButton( false ), aRequestedClientPoint ) )
return m_pImpl->getTabBar()->GetScrollButton( false ).GetAccessible();
const bool bHasScrollForward = m_pImpl->getTabBar()->GetScrollButton( true ).IsVisible();
if ( bHasScrollForward && lcl_covers( m_pImpl->getTabBar()->GetScrollButton( true ), aRequestedClientPoint ) )
return m_pImpl->getTabBar()->GetScrollButton( true ).GetAccessible();
// no hit
return NULL;
}
void SAL_CALL AccessibleToolPanelTabBar::disposing()
{
AccessibleToolPanelTabBar_Base::disposing();
m_pImpl->dispose();
}
Reference< XAccessible > AccessibleToolPanelTabBar::GetChildAccessible( const VclWindowEvent& i_rVclWindowEvent )
{
// don't let the base class generate any A11Y events from VclWindowEvent, we completely manage those
// A11Y events ourself
(void)i_rVclWindowEvent;
return NULL;
}
void AccessibleToolPanelTabBar::FillAccessibleStateSet( ::utl::AccessibleStateSetHelper& i_rStateSet )
{
AccessibleToolPanelTabBar_Base::FillAccessibleStateSet( i_rStateSet );
i_rStateSet.AddState( AccessibleStateType::FOCUSABLE );
ENSURE_OR_RETURN_VOID( !m_pImpl->isDisposed(), "AccessibleToolPanelTabBar::FillAccessibleStateSet: already disposed!" );
if ( m_pImpl->getTabBar()->IsVertical() )
i_rStateSet.AddState( AccessibleStateType::VERTICAL );
else
i_rStateSet.AddState( AccessibleStateType::HORIZONTAL );
}
} // namespace accessibility
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|