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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
|
/* -*- 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 <string.h>
#include <standard/vclxaccessibletoolbox.hxx>
#include <standard/vclxaccessibletoolboxitem.hxx>
#include <toolkit/helper/convert.hxx>
#include <com/sun/star/accessibility/AccessibleEventId.hpp>
#include <com/sun/star/accessibility/AccessibleStateType.hpp>
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
#include <o3tl/safeint.hxx>
#include <vcl/toolbox.hxx>
#include <vcl/vclevent.hxx>
#include <comphelper/accessiblecontexthelper.hxx>
#include <comphelper/accessiblewrapper.hxx>
#include <comphelper/processfactory.hxx>
#include <comphelper/servicehelper.hxx>
#include <comphelper/types.hxx>
using namespace ::comphelper;
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::accessibility;
namespace
{
// = OToolBoxWindowItemContext
/** XAccessibleContext implementation for a toolbox item which is represented by a VCL Window
*/
class OToolBoxWindowItemContext final : public OAccessibleContextWrapper
{
sal_Int32 m_nIndexInParent;
public:
OToolBoxWindowItemContext(sal_Int32 _nIndexInParent,
const css::uno::Reference< css::uno::XComponentContext >& _rxContext,
const css::uno::Reference< css::accessibility::XAccessibleContext >& _rxInnerAccessibleContext,
const css::uno::Reference< css::accessibility::XAccessible >& _rxOwningAccessible,
const css::uno::Reference< css::accessibility::XAccessible >& _rxParentAccessible
) : OAccessibleContextWrapper(
_rxContext,
_rxInnerAccessibleContext,
_rxOwningAccessible,
_rxParentAccessible )
,m_nIndexInParent(_nIndexInParent)
{
}
virtual sal_Int64 SAL_CALL getAccessibleIndexInParent( ) override;
};
sal_Int64 SAL_CALL OToolBoxWindowItemContext::getAccessibleIndexInParent( )
{
return m_nIndexInParent;
}
// = OToolBoxWindowItem
/** XAccessible implementation for a toolbox item which is represented by a VCL Window
*/
class OToolBoxWindowItem : public OAccessibleWrapper
{
private:
sal_Int32 m_nIndexInParent;
public:
OToolBoxWindowItem(sal_Int32 _nIndexInParent,
const css::uno::Reference< css::uno::XComponentContext >& _rxContext,
const css::uno::Reference< css::accessibility::XAccessible >& _rxInnerAccessible,
const css::uno::Reference< css::accessibility::XAccessible >& _rxParentAccessible
) : OAccessibleWrapper(
_rxContext,
_rxInnerAccessible,
_rxParentAccessible)
,m_nIndexInParent(_nIndexInParent)
{
}
protected:
// OAccessibleWrapper
virtual rtl::Reference<OAccessibleContextWrapper> createAccessibleContext(
const css::uno::Reference< css::accessibility::XAccessibleContext >& _rxInnerContext
) override;
};
rtl::Reference<OAccessibleContextWrapper> OToolBoxWindowItem::createAccessibleContext(
const Reference< XAccessibleContext >& _rxInnerContext )
{
return new OToolBoxWindowItemContext( m_nIndexInParent, getComponentContext(), _rxInnerContext, this, getParent() );
}
}
// VCLXAccessibleToolBox
VCLXAccessibleToolBox::VCLXAccessibleToolBox( VCLXWindow* pVCLXWindow ) :
ImplInheritanceHelper( pVCLXWindow )
{
}
VCLXAccessibleToolBox::~VCLXAccessibleToolBox()
{
}
VCLXAccessibleToolBoxItem* VCLXAccessibleToolBox::GetItem_Impl( ToolBox::ImplToolItems::size_type _nPos )
{
VCLXAccessibleToolBoxItem* pItem = nullptr;
VclPtr< ToolBox > pToolBox = GetAs< ToolBox >();
if ( pToolBox )
{
ToolBoxItemsMap::iterator aIter = m_aAccessibleChildren.find( _nPos );
//TODO: ToolBox::ImplToolItems::size_type -> sal_Int32!
// returns only toolbox buttons, not windows
if ( aIter != m_aAccessibleChildren.end() && aIter->second.is())
pItem = aIter->second.get();
}
return pItem;
}
void VCLXAccessibleToolBox::UpdateFocus_Impl()
{
VclPtr< ToolBox > pToolBox = GetAs< ToolBox >();
if( !pToolBox )
return;
// submit events only if toolbox has the focus to avoid sending events due to mouse move
bool bHasFocus = false;
if ( pToolBox->HasFocus() )
bHasFocus = true;
else
{
// check for subtoolbar, i.e. check if our parent is a toolbar
ToolBox* pToolBoxParent = dynamic_cast< ToolBox* >( pToolBox->GetParent() );
// subtoolbars never get the focus as key input is just forwarded, so check if the parent toolbar has it
if ( pToolBoxParent && pToolBoxParent->HasFocus() )
bHasFocus = true;
}
if ( !bHasFocus )
return;
ToolBoxItemId nHighlightItemId = pToolBox->GetHighlightItemId();
sal_uInt16 nFocusCount = 0;
for ( const auto& [rPos, rxChild] : m_aAccessibleChildren )
{
ToolBoxItemId nItemId = pToolBox->GetItemId( rPos );
if ( rxChild.is() )
{
VCLXAccessibleToolBoxItem* pItem = rxChild.get();
if ( pItem->HasFocus() && nItemId != nHighlightItemId )
{
// reset the old focused item
pItem->SetFocus( false );
nFocusCount++;
}
if ( nItemId == nHighlightItemId )
{
// set the new focused item
pItem->SetFocus( true );
nFocusCount++;
}
}
// both items changed?
if ( nFocusCount > 1 )
break;
}
}
void VCLXAccessibleToolBox::ReleaseFocus_Impl( ToolBox::ImplToolItems::size_type _nPos )
{
VclPtr< ToolBox > pToolBox = GetAs< ToolBox >();
if ( pToolBox ) // #107124#, do not check for focus because this message is also handled in losefocus
{
ToolBoxItemsMap::iterator aIter = m_aAccessibleChildren.find( _nPos );
//TODO: ToolBox::ImplToolItems::size_type -> sal_Int32!
if ( aIter != m_aAccessibleChildren.end() && aIter->second.is() )
{
VCLXAccessibleToolBoxItem* pItem = aIter->second.get();
if ( pItem->HasFocus() )
pItem->SetFocus( false );
}
}
}
void VCLXAccessibleToolBox::UpdateChecked_Impl( ToolBox::ImplToolItems::size_type _nPos )
{
VclPtr< ToolBox > pToolBox = GetAs< ToolBox >();
if ( !pToolBox )
return;
ToolBoxItemId nFocusId = pToolBox->GetItemId( _nPos );
VCLXAccessibleToolBoxItem* pFocusItem = nullptr;
for ( const auto& [rPos, rxChild] : m_aAccessibleChildren )
{
ToolBoxItemId nItemId = pToolBox->GetItemId( rPos );
VCLXAccessibleToolBoxItem* pItem = rxChild.get();
pItem->SetChecked( pToolBox->IsItemChecked( nItemId ) );
if ( nItemId == nFocusId )
pFocusItem = pItem;
}
//Solution:If the position is not a child item,the focus should not be called
if ( pFocusItem && _nPos != ToolBox::ITEM_NOTFOUND )
pFocusItem->SetFocus( true );
}
void VCLXAccessibleToolBox::UpdateIndeterminate_Impl( ToolBox::ImplToolItems::size_type _nPos )
{
VclPtr< ToolBox > pToolBox = GetAs< ToolBox >();
if ( !pToolBox )
return;
ToolBoxItemId nItemId = pToolBox->GetItemId( _nPos );
ToolBoxItemsMap::iterator aIter = m_aAccessibleChildren.find( _nPos );
//TODO: ToolBox::ImplToolItems::size_type -> sal_Int32!
if ( aIter != m_aAccessibleChildren.end() && aIter->second.is() )
{
VCLXAccessibleToolBoxItem* pItem = aIter->second.get();
if ( pItem )
pItem->SetIndeterminate( pToolBox->GetItemState( nItemId ) == TRISTATE_INDET );
}
}
void VCLXAccessibleToolBox::implReleaseToolboxItem( ToolBoxItemsMap::iterator const & _rMapPos,
bool _bNotifyRemoval )
{
rtl::Reference<VCLXAccessibleToolBoxItem> xItemAcc(_rMapPos->second);
if ( !xItemAcc.is() )
return;
if ( _bNotifyRemoval )
{
NotifyAccessibleEvent(AccessibleEventId::CHILD, Any(Reference<XAccessible>(xItemAcc)), Any());
}
xItemAcc->ReleaseToolBox();
xItemAcc->dispose();
}
void VCLXAccessibleToolBox::UpdateItem_Impl( ToolBox::ImplToolItems::size_type _nPos)
{
if ( _nPos < m_aAccessibleChildren.size() )
{
UpdateAllItems_Impl();
return;
}
VclPtr< ToolBox > pToolBox = GetAs< ToolBox >();
if ( !pToolBox )
return;
// adjust the "index-in-parent"s
ToolBoxItemsMap::iterator aIndexAdjust = m_aAccessibleChildren.upper_bound( _nPos );
//TODO: ToolBox::ImplToolItems::size_type -> sal_Int32!
while ( m_aAccessibleChildren.end() != aIndexAdjust )
{
rtl::Reference<VCLXAccessibleToolBoxItem> xItem(aIndexAdjust->second);
if (xItem.is())
{
sal_Int32 nIndex = xItem->getIndexInParent();
nIndex++;
xItem->setIndexInParent(nIndex);
}
++aIndexAdjust;
}
// TODO: we should make this dependent on the existence of event listeners
// with the current implementation, we always create accessible object
Any aNewChild( getAccessibleChild( static_cast<sal_Int64>(_nPos) ) );
//TODO: ToolBox::ImplToolItems::size_type -> sal_Int32!
NotifyAccessibleEvent( AccessibleEventId::CHILD, Any(), aNewChild );
}
void VCLXAccessibleToolBox::UpdateAllItems_Impl()
{
VclPtr< ToolBox > pToolBox = GetAs< ToolBox >();
if ( !pToolBox )
return;
// deregister the old items
for ( ToolBoxItemsMap::iterator aIter = m_aAccessibleChildren.begin();
aIter != m_aAccessibleChildren.end(); ++aIter )
{
implReleaseToolboxItem( aIter, true );
}
m_aAccessibleChildren.clear();
// register the new items
ToolBox::ImplToolItems::size_type i, nCount = pToolBox->GetItemCount();
for ( i = 0; i < nCount; ++i )
{
Any aNewValue;
aNewValue <<= getAccessibleChild(i);
NotifyAccessibleEvent( AccessibleEventId::CHILD, Any(), aNewValue );
}
}
void VCLXAccessibleToolBox::UpdateCustomPopupItemp_Impl( vcl::Window* pWindow, bool bOpen )
{
VclPtr< ToolBox > pToolBox = GetAs< ToolBox >();
if( !(pWindow && pToolBox) )
return;
const ToolBoxItemId nDownItem = pToolBox->GetDownItemId();
if ( !nDownItem )
// No item is currently in down state.
// Moreover, calling GetItemPos with 0 will find a separator if there is any.
return;
Reference< XAccessible > xChild( pWindow->GetAccessible() );
if( xChild.is() )
{
Reference< XAccessible > xChildItem( getAccessibleChild(pToolBox->GetItemPos(nDownItem)));
VCLXAccessibleToolBoxItem* pItem = static_cast< VCLXAccessibleToolBoxItem* >( xChildItem.get() );
pItem->SetChild( xChild );
pItem->NotifyChildEvent( xChild, bOpen );
}
}
void VCLXAccessibleToolBox::UpdateItemName_Impl( ToolBox::ImplToolItems::size_type _nPos )
{
VCLXAccessibleToolBoxItem* pItem = GetItem_Impl( _nPos );
if ( pItem )
pItem->NameChanged();
}
void VCLXAccessibleToolBox::UpdateItemEnabled_Impl( ToolBox::ImplToolItems::size_type _nPos )
{
VCLXAccessibleToolBoxItem* pItem = GetItem_Impl( _nPos );
if ( pItem )
pItem->ToggleEnableState();
}
void VCLXAccessibleToolBox::HandleSubToolBarEvent( const VclWindowEvent& rVclWindowEvent )
{
vcl::Window* pChildWindow = static_cast<vcl::Window *>(rVclWindowEvent.GetData());
VclPtr< ToolBox > pToolBox = GetAs< ToolBox >();
if ( !(pChildWindow
&& pToolBox
&& pToolBox == pChildWindow->GetParent()
&& pChildWindow->GetType() == WindowType::TOOLBOX) )
return;
const ToolBoxItemId nCurItemId( pToolBox->GetCurItemId() );
if ( !nCurItemId )
// No item is currently active (might happen when opening the overflow popup).
// Moreover, calling GetItemPos with 0 will find a separator if there is any.
return;
ToolBox::ImplToolItems::size_type nIndex = pToolBox->GetItemPos( nCurItemId );
Reference< XAccessible > xItem = getAccessibleChild( nIndex );
if ( xItem.is() )
{
Reference< XAccessible > xChild = pChildWindow->GetAccessible();
VCLXAccessibleToolBoxItem* pItem =
static_cast< VCLXAccessibleToolBoxItem* >( xItem.get() );
pItem->SetChild( xChild );
pItem->NotifyChildEvent( xChild, true/*_bShow*/ );
}
}
void VCLXAccessibleToolBox::ReleaseSubToolBox( ToolBox* _pSubToolBox )
{
VclPtr< ToolBox > pToolBox = GetAs< ToolBox >();
if ( !pToolBox )
return;
ToolBox::ImplToolItems::size_type nIndex = pToolBox->GetItemPos( pToolBox->GetCurItemId() );
if ( nIndex == ToolBox::ITEM_NOTFOUND )
return; // not found
Reference< XAccessible > xItem = getAccessibleChild( nIndex );
if ( !xItem.is() )
return;
Reference< XAccessible > xChild = _pSubToolBox->GetAccessible();
VCLXAccessibleToolBoxItem* pItem =
static_cast< VCLXAccessibleToolBoxItem* >( xItem.get() );
if ( pItem->GetChild() == xChild )
{
pItem->SetChild( Reference< XAccessible >() );
pItem->NotifyChildEvent( xChild, false );
}
}
void VCLXAccessibleToolBox::FillAccessibleStateSet( sal_Int64& rStateSet )
{
VCLXAccessibleComponent::FillAccessibleStateSet( rStateSet );
VclPtr< ToolBox > pToolBox = GetAs< ToolBox >();
if ( pToolBox )
{
rStateSet |= AccessibleStateType::FOCUSABLE;
if ( pToolBox->IsHorizontal() )
rStateSet |= AccessibleStateType::HORIZONTAL;
else
rStateSet |= AccessibleStateType::VERTICAL;
}
}
void VCLXAccessibleToolBox::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
{
// to prevent an early release of the toolbox (VclEventId::ObjectDying)
Reference< XAccessibleContext > xHoldAlive = this;
switch ( rVclWindowEvent.GetId() )
{
case VclEventId::ToolboxClick:
case VclEventId::ToolboxSelect:
{
VclPtr< ToolBox > pToolBox = GetAs< ToolBox >();
if ( rVclWindowEvent.GetData() )
{
UpdateChecked_Impl( static_cast<ToolBox::ImplToolItems::size_type>(reinterpret_cast<sal_IntPtr>(rVclWindowEvent.GetData())) );
UpdateIndeterminate_Impl( static_cast<ToolBox::ImplToolItems::size_type>(reinterpret_cast<sal_IntPtr>(rVclWindowEvent.GetData())) );
}
else if( pToolBox->GetItemPos(pToolBox->GetCurItemId()) != ToolBox::ITEM_NOTFOUND )
{
UpdateChecked_Impl( pToolBox->GetItemPos(pToolBox->GetCurItemId()) );
UpdateIndeterminate_Impl( pToolBox->GetItemPos(pToolBox->GetCurItemId()) );
}
break;
}
case VclEventId::ToolboxDoubleClick:
case VclEventId::ToolboxActivate:
case VclEventId::ToolboxDeactivate:
//case VclEventId::ToolboxSelect:
break;
case VclEventId::ToolboxItemUpdated:
{
if ( rVclWindowEvent.GetData() )
{
UpdateChecked_Impl( ToolBox::ITEM_NOTFOUND );
UpdateIndeterminate_Impl( static_cast<ToolBox::ImplToolItems::size_type>(reinterpret_cast<sal_IntPtr>(rVclWindowEvent.GetData())) );
}
break;
}
case VclEventId::ToolboxHighlight:
UpdateFocus_Impl();
break;
case VclEventId::ToolboxHighlightOff:
ReleaseFocus_Impl( static_cast<ToolBox::ImplToolItems::size_type>(reinterpret_cast<sal_IntPtr>(rVclWindowEvent.GetData())) );
break;
case VclEventId::ToolboxItemAdded :
UpdateItem_Impl( static_cast<ToolBox::ImplToolItems::size_type>(reinterpret_cast<sal_IntPtr>(rVclWindowEvent.GetData())) );
break;
case VclEventId::ToolboxItemRemoved :
case VclEventId::ToolboxAllItemsChanged :
{
UpdateAllItems_Impl();
break;
}
case VclEventId::ToolboxItemWindowChanged:
{
auto nPos = static_cast<ToolBox::ImplToolItems::size_type>(reinterpret_cast<sal_IntPtr>(rVclWindowEvent.GetData()));
ToolBoxItemsMap::iterator aAccessiblePos( m_aAccessibleChildren.find( nPos ) );
//TODO: ToolBox::ImplToolItems::size_type -> sal_Int32!
if ( m_aAccessibleChildren.end() != aAccessiblePos )
{
implReleaseToolboxItem( aAccessiblePos, false );
m_aAccessibleChildren.erase (aAccessiblePos);
}
Any aNewValue;
aNewValue <<= getAccessibleChild(nPos);
NotifyAccessibleEvent( AccessibleEventId::CHILD, Any(), aNewValue );
break;
}
case VclEventId::ToolboxItemTextChanged :
UpdateItemName_Impl( static_cast<ToolBox::ImplToolItems::size_type>(reinterpret_cast<sal_IntPtr>(rVclWindowEvent.GetData())) );
break;
case VclEventId::ToolboxItemEnabled :
case VclEventId::ToolboxItemDisabled :
{
UpdateItemEnabled_Impl( static_cast<ToolBox::ImplToolItems::size_type>(reinterpret_cast<sal_IntPtr>(rVclWindowEvent.GetData())) );
break;
}
case VclEventId::DropdownOpen:
case VclEventId::DropdownClose:
{
UpdateCustomPopupItemp_Impl( static_cast< vcl::Window* >( rVclWindowEvent.GetData() ), rVclWindowEvent.GetId() == VclEventId::DropdownOpen );
break;
}
case VclEventId::ObjectDying :
{
// if this toolbox is a subtoolbox, we have to release it from its parent
VclPtr< vcl::Window > pWin = GetAs< vcl::Window >();
if ( pWin && pWin->GetParent() &&
pWin->GetParent()->GetType() == WindowType::TOOLBOX )
{
auto pParentAccContext = pWin->GetParent()->GetAccessible()->getAccessibleContext();
VCLXAccessibleToolBox* pParent = static_cast< VCLXAccessibleToolBox* >( pParentAccContext.get() );
if ( pParent )
pParent->ReleaseSubToolBox(static_cast<ToolBox *>(pWin.get()));
}
// dispose all items
for ( ToolBoxItemsMap::iterator aIter = m_aAccessibleChildren.begin();
aIter != m_aAccessibleChildren.end(); ++aIter )
{
implReleaseToolboxItem( aIter, false );
}
m_aAccessibleChildren.clear();
[[fallthrough]]; // call base class
}
default:
VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent );
}
}
void VCLXAccessibleToolBox::ProcessWindowChildEvent( const VclWindowEvent& rVclWindowEvent )
{
switch ( rVclWindowEvent.GetId() )
{
case VclEventId::WindowShow: // send create on show for direct accessible children
{
Reference< XAccessible > xReturn = GetItemWindowAccessible(rVclWindowEvent);
if ( xReturn.is() )
NotifyAccessibleEvent( AccessibleEventId::CHILD, Any(), Any(xReturn) );
else
HandleSubToolBarEvent( rVclWindowEvent );
}
break;
default:
VCLXAccessibleComponent::ProcessWindowChildEvent( rVclWindowEvent );
}
}
// XComponent
void SAL_CALL VCLXAccessibleToolBox::disposing()
{
VCLXAccessibleComponent::disposing();
// release the items
for ( ToolBoxItemsMap::iterator aIter = m_aAccessibleChildren.begin();
aIter != m_aAccessibleChildren.end(); ++aIter )
{
implReleaseToolboxItem( aIter, false );
}
m_aAccessibleChildren.clear();
}
// XServiceInfo
OUString VCLXAccessibleToolBox::getImplementationName()
{
return "com.sun.star.comp.toolkit.AccessibleToolBox";
}
Sequence< OUString > VCLXAccessibleToolBox::getSupportedServiceNames()
{
return comphelper::concatSequences(VCLXAccessibleComponent::getSupportedServiceNames(),
Sequence<OUString>{"com.sun.star.accessibility.AccessibleToolBox"});
}
// XAccessibleContext
sal_Int64 SAL_CALL VCLXAccessibleToolBox::getAccessibleChildCount( )
{
comphelper::OExternalLockGuard aGuard( this );
return implGetAccessibleChildCount();
}
sal_Int64 VCLXAccessibleToolBox::implGetAccessibleChildCount( )
{
sal_Int64 nCount = 0;
VclPtr< ToolBox > pToolBox = GetAs< ToolBox >();
if ( pToolBox )
nCount = pToolBox->GetItemCount();
return nCount;
}
Reference< XAccessible > SAL_CALL VCLXAccessibleToolBox::getAccessibleChild( sal_Int64 i )
{
comphelper::OExternalLockGuard aGuard( this );
VclPtr< ToolBox > pToolBox = GetAs< ToolBox >();
if ( (!pToolBox) || i < 0 || o3tl::make_unsigned(i) >= pToolBox->GetItemCount() )
throw IndexOutOfBoundsException();
rtl::Reference< VCLXAccessibleToolBoxItem > xChild;
// search for the child
ToolBoxItemsMap::iterator aIter = m_aAccessibleChildren.find(i);
if ( m_aAccessibleChildren.end() == aIter )
{
ToolBoxItemId nItemId = pToolBox->GetItemId( i );
ToolBoxItemId nHighlightItemId = pToolBox->GetHighlightItemId();
vcl::Window* pItemWindow = pToolBox->GetItemWindow( nItemId );
// not found -> create a new child
xChild = new VCLXAccessibleToolBoxItem( pToolBox, i );
if ( pItemWindow )
{
Reference< XAccessible> xParent = xChild;
auto const xInnerAcc(pItemWindow->GetAccessible());
if (xInnerAcc) // else child is being disposed - avoid crashing
{
rtl::Reference<OToolBoxWindowItem> xChild2(new OToolBoxWindowItem(0,
::comphelper::getProcessComponentContext(), xInnerAcc, xParent));
pItemWindow->SetAccessible(xChild2);
xChild->SetChild( xChild2 );
}
}
if ( nHighlightItemId > ToolBoxItemId(0) && nItemId == nHighlightItemId )
xChild->SetFocus( true );
if ( pToolBox->IsItemChecked( nItemId ) )
xChild->SetChecked( true );
if ( pToolBox->GetItemState( nItemId ) == TRISTATE_INDET )
xChild->SetIndeterminate( true );
m_aAccessibleChildren.emplace( i, xChild );
}
else
{
// found it
xChild = aIter->second;
}
return xChild;
}
Reference< XAccessible > SAL_CALL VCLXAccessibleToolBox::getAccessibleAtPoint( const awt::Point& _rPoint )
{
comphelper::OExternalLockGuard aGuard( this );
Reference< XAccessible > xAccessible;
VclPtr< ToolBox > pToolBox = GetAs< ToolBox >();
if ( pToolBox )
{
ToolBox::ImplToolItems::size_type nItemPos = pToolBox->GetItemPos( VCLPoint( _rPoint ) );
if ( nItemPos != ToolBox::ITEM_NOTFOUND )
xAccessible = getAccessibleChild( nItemPos );
}
return xAccessible;
}
Reference< XAccessible > VCLXAccessibleToolBox::GetItemWindowAccessible( const VclWindowEvent& rVclWindowEvent )
{
Reference< XAccessible > xReturn;
vcl::Window* pChildWindow = static_cast<vcl::Window *>(rVclWindowEvent.GetData());
VclPtr< ToolBox > pToolBox = GetAs< ToolBox >();
if ( pChildWindow && pToolBox )
{
ToolBox::ImplToolItems::size_type nCount = pToolBox->GetItemCount();
for (ToolBox::ImplToolItems::size_type i = 0 ; i < nCount && !xReturn.is() ; ++i)
{
ToolBoxItemId nItemId = pToolBox->GetItemId( i );
vcl::Window* pItemWindow = pToolBox->GetItemWindow( nItemId );
if ( pItemWindow == pChildWindow )
xReturn = getAccessibleChild(i);
}
}
return xReturn;
}
Reference< XAccessible > VCLXAccessibleToolBox::GetChildAccessible( const VclWindowEvent& rVclWindowEvent )
{
Reference< XAccessible > xReturn = GetItemWindowAccessible(rVclWindowEvent);
if ( !xReturn.is() )
xReturn = VCLXAccessibleComponent::GetChildAccessible(rVclWindowEvent);
return xReturn;
}
// XAccessibleSelection
void VCLXAccessibleToolBox::selectAccessibleChild( sal_Int64 nChildIndex )
{
OExternalLockGuard aGuard( this );
VclPtr< ToolBox > pToolBox = GetAs< ToolBox >();
if ( (!pToolBox) || nChildIndex < 0 || o3tl::make_unsigned(nChildIndex) >= pToolBox->GetItemCount() )
throw IndexOutOfBoundsException();
pToolBox->ChangeHighlight( nChildIndex );
}
sal_Bool VCLXAccessibleToolBox::isAccessibleChildSelected( sal_Int64 nChildIndex )
{
OExternalLockGuard aGuard( this );
VclPtr< ToolBox > pToolBox = GetAs< ToolBox >();
if ( (!pToolBox) || nChildIndex < 0 || o3tl::make_unsigned(nChildIndex) >= pToolBox->GetItemCount() )
throw IndexOutOfBoundsException();
if ( pToolBox->GetHighlightItemId() == pToolBox->GetItemId( nChildIndex ) )
return true;
else
return false;
}
void VCLXAccessibleToolBox::clearAccessibleSelection( )
{
OExternalLockGuard aGuard( this );
VclPtr< ToolBox > pToolBox = GetAs< ToolBox >();
pToolBox -> LoseFocus();
}
void VCLXAccessibleToolBox::selectAllAccessibleChildren( )
{
OExternalLockGuard aGuard( this );
// intentionally empty. makes no sense for a toolbox
}
sal_Int64 VCLXAccessibleToolBox::getSelectedAccessibleChildCount( )
{
OExternalLockGuard aGuard( this );
sal_Int64 nRet = 0;
VclPtr< ToolBox > pToolBox = GetAs< ToolBox >();
if (pToolBox)
{
ToolBoxItemId nHighlightItemId = pToolBox->GetHighlightItemId();
for ( size_t i = 0, nCount = pToolBox->GetItemCount(); i < nCount; i++ )
{
if ( nHighlightItemId == pToolBox->GetItemId( i ) )
{
nRet = 1;
break; // a toolbox can only have (n)one selected child
}
}
}
return nRet;
}
Reference< XAccessible > VCLXAccessibleToolBox::getSelectedAccessibleChild( sal_Int64 nSelectedChildIndex )
{
OExternalLockGuard aGuard( this );
if ( nSelectedChildIndex != 0 )
throw IndexOutOfBoundsException();
Reference< XAccessible > xChild;
VclPtr< ToolBox > pToolBox = GetAs< ToolBox >();
if (pToolBox)
{
ToolBoxItemId nHighlightItemId = pToolBox->GetHighlightItemId();
for (ToolBox::ImplToolItems::size_type i = 0, nCount = pToolBox->GetItemCount(); i < nCount; i++ )
{
if ( nHighlightItemId == pToolBox->GetItemId( i ) )
{
xChild = getAccessibleChild( i );
break;
}
}
}
if (!xChild)
throw IndexOutOfBoundsException();
return xChild;
}
void VCLXAccessibleToolBox::deselectAccessibleChild( sal_Int64 nChildIndex )
{
OExternalLockGuard aGuard( this );
if ( nChildIndex < 0 || nChildIndex >= implGetAccessibleChildCount() )
throw IndexOutOfBoundsException();
clearAccessibleSelection(); // a toolbox can only have (n)one selected child
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|