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
|
/*************************************************************************
*
* $RCSfile: ChildrenManagerImpl.cxx,v $
*
* $Revision: 1.13 $
*
* last change: $Author: af $ $Date: 2002-05-17 16:11:41 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (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.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
#include "ChildrenManagerImpl.hxx"
#ifndef _SVX_ACCESSIBILITY_SHAPE_TYPE_HANDLER_HXX
#include "ShapeTypeHandler.hxx"
#endif
#ifndef _SVX_ACCESSIBILITY_ACCESSIBLE_SHAPE_INFO_HXX
#include "AccessibleShapeInfo.hxx"
#endif
#ifndef _DRAFTS_COM_SUN_STAR_ACCESSIBLE_ACCESSIBLESTATETYPE_HPP_
#include <drafts/com/sun/star/accessibility/AccessibleStateType.hpp>
#endif
#ifndef _COM_SUN_STAR_VIEW_XSELECTIONSUPPLIER_HPP_
#include <com/sun/star/view/XSelectionSupplier.hpp>
#endif
using namespace ::rtl;
using namespace ::com::sun::star;
using namespace ::drafts::com::sun::star::accessibility;
using ::com::sun::star::uno::Reference;
namespace accessibility {
struct ChildDescriptor; // See below for declaration.
//===== AccessibleChildrenManager ===========================================
ChildrenManagerImpl::ChildrenManagerImpl (
const uno::Reference<XAccessible>& rxParent,
const uno::Reference<drawing::XShapes>& rxShapeList,
const AccessibleShapeTreeInfo& rShapeTreeInfo,
AccessibleContextBase& rContext)
: mxShapeList (rxShapeList),
mxParent (rxParent),
maShapeTreeInfo (rShapeTreeInfo),
mrContext (rContext)
{
OSL_TRACE ("creating new children manager with %d children", rxShapeList->getCount());
}
ChildrenManagerImpl::~ChildrenManagerImpl (void)
{
ClearAccessibleShapeList ();
OSL_TRACE ("~ChildrenManagerImpl");
}
void ChildrenManagerImpl::Init (void)
{
/*
// Register as document::XEventListener.
if (maShapeTreeInfo.GetModelBroadcaster().is())
maShapeTreeInfo.GetModelBroadcaster()->addEventListener (
static_cast<document::XEventListener*>(this));
*/
}
long ChildrenManagerImpl::GetChildCount (void) const throw ()
{
return maVisibleChildren.size();
}
/** Return the requested accessible child object. Create it if it is not
yet in the cache.
*/
uno::Reference<XAccessible>
ChildrenManagerImpl::GetChild (long nIndex)
throw (::com::sun::star::uno::RuntimeException)
{
// Check wether the given index is valid.
if (nIndex < 0 || (unsigned long)nIndex >= maVisibleChildren.size())
throw lang::IndexOutOfBoundsException (
::rtl::OUString::createFromAscii ("no accessible child with index ") + nIndex,
mxParent);
return GetChild (maVisibleChildren[nIndex]);
}
/** Return the requested accessible child object. Create it if it is not
yet in the cache.
*/
uno::Reference<XAccessible>
ChildrenManagerImpl::GetChild (ChildDescriptor& rChildDescriptor)
throw (::com::sun::star::uno::RuntimeException)
{
bool bChildHasBeenCreated = false;
if ( ! rChildDescriptor.mxAccessibleShape.is())
{
::vos::OGuard aGuard (maMutex);
// ::osl::Guard< ::osl::Mutex> aGuard (::osl::Mutex::getGlobalMutex());
// Make sure that the requested accessible object has not been
// created while locking the global mutex.
if ( ! rChildDescriptor.mxAccessibleShape.is())
{
// Create accessible object that corresponds to the descriptor's
// shape.
AccessibleShape* pShape =
ShapeTypeHandler::Instance().CreateAccessibleObject (
AccessibleShapeInfo (
rChildDescriptor.mxShape,
mxParent,
this),
maShapeTreeInfo);
// rChildDescriptor.mpAccessibleShape = pShape;
rChildDescriptor.mxAccessibleShape = uno::Reference<XAccessible> (
static_cast<uno::XWeak*>(pShape),
uno::UNO_QUERY);
// Remember that the child has been created to inform the
// listeners after unlocking the global mutex.
bChildHasBeenCreated = rChildDescriptor.mxAccessibleShape.is();
}
}
return rChildDescriptor.mxAccessibleShape;
}
uno::Reference<XAccessible>
ChildrenManagerImpl::GetChild (const uno::Reference<drawing::XShape>& xShape)
throw (uno::RuntimeException)
{
ChildDescriptorListType::iterator I;
for (I=maVisibleChildren.begin(); I!=maVisibleChildren.end(); I++)
{
if (I->mxShape == xShape)
return I->mxAccessibleShape;
}
return uno::Reference<XAccessible> ();
}
/** Find all shapes among the specified shapes that lie fully or partially
inside the visible area. Put those shapes into the cleared cache. The
corresponding accessible objects will be created on demand.
At the moment, first all accessible objects are removed from the cache
and the appropriate listeners are informed of this. Next, the list is
created again. This should be optimized in the future to not remove and
create objects that will be in the list before and after the update
method.
*/
void ChildrenManagerImpl::Update (bool bCreateNewObjectsOnDemand)
{
if (maShapeTreeInfo.GetViewForwarder() == NULL)
return;
Rectangle aVisibleArea = maShapeTreeInfo.GetViewForwarder()->GetVisibleArea();
OSL_TRACE ("ChildrenManagerImpl::update called with VisibleArea = %d %d %d %d",
aVisibleArea.getX(), aVisibleArea.getY(),
aVisibleArea.getWidth(), aVisibleArea.getHeight());
// 1. Create a local list of visible shapes.
ChildDescriptorListType aNewChildList;
CreateListOfVisibleShapes (aNewChildList);
// 2. Find all shapes in the current list that are not in the new list,
// send appropriate events and remove the accessible shape.
RemoveNonVisibleChildren (aNewChildList);
// 3. Merge the information that is already known about the visible
// shapes from the current list into the new list.
MergeAccessibilityInformation (aNewChildList);
// 4. If the visible area has changed then send events that signal a
// change of their bounding boxes for all shapes that are members of
// both the current and the new list of visible shapes.
if (maVisibleArea != aVisibleArea)
SendVisibleAreaEvents (aNewChildList);
// 5. If children have to be created immediately and not on demand the
// create the missing accessible objects now.
if ( ! bCreateNewObjectsOnDemand)
CreateAccessibilityObjects (aNewChildList);
// 6. Replace the current list of visible shapes with the new one. Do
// the same with the visible area.
::vos::OGuard aGuard (maMutex);
maVisibleChildren = aNewChildList;
maVisibleArea = aVisibleArea;
}
void ChildrenManagerImpl::CreateListOfVisibleShapes (
ChildDescriptorListType& raDescriptorList)
{
::vos::OGuard aGuard (maMutex);
OSL_ASSERT (maShapeTreeInfo.GetViewForwarder() != NULL);
Rectangle aVisibleArea = maShapeTreeInfo.GetViewForwarder()->GetVisibleArea();
// Add the visible shapes for wich the accessible objects already exist.
AccessibleShapeList::iterator I;
for (I=maAccessibleShapes.begin(); I!=maAccessibleShapes.end(); ++I)
{
if (I->is())
{
uno::Reference<XAccessibleComponent> xComponent (
(*I)->getAccessibleContext(), uno::UNO_QUERY);
if (xComponent.is())
{
// The bounding box of the object already is clipped to the
// visible area. The object is therefore visible if the
// bounding box has non-zero extensions.
awt::Rectangle aPixelBBox (xComponent->getBounds());
if ((aPixelBBox.Width > 0) && (aPixelBBox.Height > 0))
raDescriptorList.push_back (ChildDescriptor (*I));
else
OSL_TRACE ("accessible shape %x not visible", *I);
}
}
}
// Add the visible shapes for which only the XShapes exist.
uno::Reference<container::XIndexAccess> xShapeAccess (mxShapeList, uno::UNO_QUERY);
if (xShapeAccess.is())
{
sal_Int32 nShapeCount = xShapeAccess->getCount();
for (sal_Int32 i=0; i<nShapeCount; i++)
{
uno::Reference<drawing::XShape> xShape;
xShapeAccess->getByIndex(i) >>= xShape;
Rectangle aBoundingBox (
xShape->getPosition().X,
xShape->getPosition().Y,
xShape->getPosition().X + xShape->getSize().Width,
xShape->getPosition().Y + xShape->getSize().Height);
// Insert shape if it is visible, i.e. its bounding box overlaps
// the visible area.
if (aBoundingBox.IsOver (aVisibleArea))
raDescriptorList.push_back (ChildDescriptor (xShape));
else
OSL_TRACE ("shape %x not visible", xShape);
}
}
}
void ChildrenManagerImpl::RemoveNonVisibleChildren (
ChildDescriptorListType& raNewChildList)
{
// Iterate over list of formerly visible children and remove those that
// are not visible anymore, i.e. member of the new list of visible
// children.
ChildDescriptorListType::iterator I;
for (I=maVisibleChildren.begin(); I!=maVisibleChildren.end(); I++)
{
if (find (raNewChildList.begin(), raNewChildList.end(), *I) == raNewChildList.end())
{
OSL_TRACE ("child no longer visible");
if (I->mxAccessibleShape.is())
{
// Send event that the shape has been removed.
uno::Any aOldValue;
aOldValue <<= I->mxAccessibleShape;
mrContext.CommitChange (
AccessibleEventId::ACCESSIBLE_CHILD_EVENT,
uno::Any(),
aOldValue);
// Dispose and remove the object.
if (I->mxShape.is())
{
Reference<lang::XComponent> xComponent (I->mxAccessibleShape, uno::UNO_QUERY);
xComponent->dispose ();
I->mxAccessibleShape = NULL;
}
}
}
}
}
void ChildrenManagerImpl::MergeAccessibilityInformation (
ChildDescriptorListType& raNewChildList)
{
ChildDescriptorListType::iterator aOldChildDescriptor;
ChildDescriptorListType::iterator I;
for (I=raNewChildList.begin(); I!=raNewChildList.end(); I++)
{
aOldChildDescriptor = find (maVisibleChildren.begin(), maVisibleChildren.end(), *I);
// Copy accessible shape if that exists in the old descriptor.
if (aOldChildDescriptor != maVisibleChildren.end())
if (aOldChildDescriptor->mxAccessibleShape.is())
{
I->mxAccessibleShape = aOldChildDescriptor->mxAccessibleShape;
// I->mpAccessibleShape = aOldChildDescriptor->mpAccessibleShape;
I->mbCreateEventPending = false;
}
}
}
void ChildrenManagerImpl::SendVisibleAreaEvents (
ChildDescriptorListType& raNewChildList)
{
ChildDescriptorListType::iterator I;
for (I=raNewChildList.begin(); I!=raNewChildList.end(); I++)
{
// Tell shape of changed visible area. To do this, fake a
// change of the view forwarder. (Actually we usually get here
// as a result of a change of the view forwarder).
AccessibleShape* pShape = I->GetAccessibleShape ();
if (pShape != NULL)
pShape->ViewForwarderChanged (
IAccessibleViewForwarderListener::VISIBLE_AREA,
maShapeTreeInfo.GetViewForwarder());
}
}
void ChildrenManagerImpl::CreateAccessibilityObjects (
ChildDescriptorListType& raNewChildList)
{
OSL_TRACE ("sending events for new shape");
ChildDescriptorListType::iterator I;
for (I=raNewChildList.begin(); I!=raNewChildList.end(); I++)
{
// Create the associated accessible object when the flag says so and
// it does not yet exist.
if ( ! I->mxAccessibleShape.is())
GetChild (*I);
if (I->mxAccessibleShape.is() && I->mbCreateEventPending)
{
uno::Any aNewShape;
aNewShape <<= I->mxAccessibleShape;
mrContext.CommitChange (
AccessibleEventId::ACCESSIBLE_CHILD_EVENT,
aNewShape,
uno::Any());
}
}
OSL_TRACE ("done sending events for new shape");
}
void ChildrenManagerImpl::SetShapeList (const ::com::sun::star::uno::Reference<
::com::sun::star::drawing::XShapes>& xShapeList)
{
mxShapeList = xShapeList;
}
void ChildrenManagerImpl::AddAccessibleShape (std::auto_ptr<AccessibleShape> pShape)
{
if (pShape.get() != NULL)
maAccessibleShapes.push_back (pShape.release());
}
void ChildrenManagerImpl::ClearAccessibleShapeList (void)
{
// Clear the list of visible accessible objects. Objects not created on
// demand for XShapes are disposed later.
ChildDescriptorListType::iterator I;
for (I=maVisibleChildren.begin(); I!=maVisibleChildren.end(); I++)
if (I->mxAccessibleShape.is() && ! I->mxShape.is())
{
uno::Any aShape;
aShape <<= I->mxAccessibleShape;
mrContext.CommitChange (
AccessibleEventId::ACCESSIBLE_CHILD_EVENT,
uno::Any(),
aShape);
// Dispose the object.
Reference<lang::XComponent> xComponent (I->mxAccessibleShape, uno::UNO_QUERY);
if (xComponent.is())
xComponent->dispose ();
I->mxAccessibleShape = NULL;
}
maVisibleChildren.clear ();
// Dispose all objects in the accessible shape list.
AccessibleShapeList::iterator J;
for (J=maAccessibleShapes.begin(); J!=maAccessibleShapes.end(); J++)
if (J->is())
{
mrContext.CommitChange (
AccessibleEventId::ACCESSIBLE_CHILD_EVENT,
uno::Any(),
uno::makeAny (*J));
// Dispose the object.
Reference<lang::XComponent> xComponent (*J, uno::UNO_QUERY);
if (xComponent.is())
xComponent->dispose ();
}
maAccessibleShapes.clear ();
}
void ChildrenManagerImpl::SetInfo (const AccessibleShapeTreeInfo& rShapeTreeInfo)
{
uno::Reference<document::XEventBroadcaster> xCurrentBroadcaster;
{
::vos::OGuard aGuard (maMutex);
xCurrentBroadcaster = maShapeTreeInfo.GetModelBroadcaster();
maShapeTreeInfo = rShapeTreeInfo;
}
if (maShapeTreeInfo.GetModelBroadcaster() != xCurrentBroadcaster)
{
// Register at new broadcaster.
if (maShapeTreeInfo.GetModelBroadcaster().is())
maShapeTreeInfo.GetModelBroadcaster()->addEventListener (
static_cast<document::XEventListener*>(this));
// Unregister at old broadcaster.
if (xCurrentBroadcaster.is())
xCurrentBroadcaster->removeEventListener (
static_cast<document::XEventListener*>(this));
}
}
//===== lang::XEventListener ================================================
void SAL_CALL
ChildrenManagerImpl::disposing (const lang::EventObject& rEventObject)
throw (uno::RuntimeException)
{
if (rEventObject.Source == maShapeTreeInfo.GetModelBroadcaster())
{
maShapeTreeInfo.SetModelBroadcaster (NULL);
// The disposing of a model should be handled elsewhere. But to be
// on the safe side we remove all of our children.
ClearAccessibleShapeList ();
SetShapeList (NULL);
}
}
//===== document::XEventListener ============================================
void SAL_CALL
ChildrenManagerImpl::notifyEvent (const document::EventObject& rEventObject)
throw (uno::RuntimeException)
{
#if 0
OSL_TRACE ("ChildrenManagerImpl::notifyEvent");
const OUString sShapeModified (RTL_CONSTASCII_USTRINGPARAM("ShapeModified"));
if (rEventObject.EventName.equals (sShapeModified))
{
OSL_TRACE (" Is ShapeNotified event");
// Some property of a shape has been modified. Find the associated
// accessible object and send an event that indicates a change of the
// visible data to all listeners.
uno::Reference<drawing::XShape> xShape (rEventObject.Source, uno::UNO_QUERY);
::vos::OGuard aGuard (maMutex);
long int i,
nCount = maVisibleChildren.size();
for (i=0; i<nCount; i++)
{
if (maVisibleChildren[i].mxShape == xShape)
{
OSL_TRACE (" Found accessible object for shape.");
ChildDescriptor& rChildDescriptor = maVisibleChildren[i];
AccessibleShape* pShape = rChildDescriptor.GetAccessibleShape();
if (pShape != NULL)
pShape->CommitChange (
AccessibleEventId::ACCESSIBLE_VISIBLE_DATA_EVENT,
uno::Any(),
uno::Any());
break;
}
}
}
#endif
}
// This method is experimental. Use with care.
long int ChildrenManagerImpl::GetChildIndex (const ::com::sun::star::uno::Reference<
::drafts::com::sun::star::accessibility::XAccessible>& xChild) const
throw (::com::sun::star::uno::RuntimeException)
{
::vos::OGuard aGuard (maMutex);
for (unsigned long i=0; i<maVisibleChildren.size(); i++)
{
// Is this equality comparison valid?
if (maVisibleChildren[i].mxAccessibleShape == xChild)
return i;
}
return -1;
}
//===== IAccessibleViewForwarderListener ====================================
void ChildrenManagerImpl::ViewForwarderChanged (ChangeType aChangeType,
const IAccessibleViewForwarder* pViewForwarder)
{
if (aChangeType == IAccessibleViewForwarderListener::VISIBLE_AREA)
Update (false);
else
{
::vos::OGuard aGuard (maMutex);
for (unsigned long i=0; i<maVisibleChildren.size(); i++)
{
AccessibleShape* pShape = maVisibleChildren[i].GetAccessibleShape();
if (pShape != NULL)
pShape->ViewForwarderChanged (aChangeType, pViewForwarder);
}
}
}
//===== IAccessibleParent ===================================================
sal_Bool ChildrenManagerImpl::ReplaceChild (
AccessibleShape* pCurrentChild,
AccessibleShape* pReplacement)
throw (uno::RuntimeException)
{
sal_Bool bResult = sal_False;
// Iterate over the visible children. If one of them has an already
// created accessible object that matches pCurrentChild then replace
// it. Otherwise the child to replace is either not in the list or has
// not ye been created (and is therefore not in the list, too) and a
// replacement is not necessary.
ChildDescriptorListType::iterator I;
for (I=maVisibleChildren.begin(); I!=maVisibleChildren.end(); I++)
{
if (I->GetAccessibleShape() == pCurrentChild)
{
// Dispose the current child and send an event about its deletion.
pCurrentChild->dispose();
mrContext.CommitChange (
AccessibleEventId::ACCESSIBLE_CHILD_EVENT,
uno::Any(),
uno::makeAny (I->mxAccessibleShape));
// Replace with replacement and send an event about existance
// of the new child.
I->mxAccessibleShape = pReplacement;
mrContext.CommitChange (
AccessibleEventId::ACCESSIBLE_CHILD_EVENT,
uno::makeAny (I->mxAccessibleShape),
uno::Any());
bResult = sal_True;
break;
}
}
// When not found among the visible children we have to search the list
// of accessible shapes. This is not yet implemented.
return bResult;
}
/** Update the selection state of all children.
Iterate over all descriptors of visible accessible shapes and look them
up in the selection.
*/
void ChildrenManagerImpl::UpdateSelection (void)
{
Reference<view::XSelectionSupplier> xSelectionSupplier (maShapeTreeInfo.GetController(), uno::UNO_QUERY);
if ( ! xSelectionSupplier.is())
return;
// Try to cast the selection both to a multi selection and to a single
// selection.
Reference<container::XIndexAccess> xSelectedShapeAccess (
xSelectionSupplier->getSelection(), uno::UNO_QUERY);
Reference<drawing::XShape> xSelectedShape (
xSelectionSupplier->getSelection(), uno::UNO_QUERY);
// Remember the current and new focused shape.
AccessibleShape* pCurrentlyFocusedShape = NULL;
AccessibleShape* pNewFocusedShape = NULL;
ChildDescriptorListType::iterator I;
for (I=maVisibleChildren.begin(); I!=maVisibleChildren.end(); I++)
{
AccessibleShape* pAccessibleShape = I->GetAccessibleShape();
if (I->mxAccessibleShape.is() && I->mxShape.is() && pAccessibleShape!=NULL)
{
bool bShapeIsSelected = false;
// Look up the shape in the selection.
if (xSelectedShape.is())
{
bShapeIsSelected = (I->mxShape == xSelectedShape);
if (bShapeIsSelected)
pNewFocusedShape = pAccessibleShape;
}
else if (xSelectedShapeAccess.is())
{
for (sal_Int32 i=0,nCount=xSelectedShapeAccess->getCount(); i<nCount&&!bShapeIsSelected; i++)
if (xSelectedShapeAccess->getByIndex(i) == I->mxShape)
{
bShapeIsSelected = true;
if (nCount == 1)
pNewFocusedShape = pAccessibleShape;
}
}
// Set or reset the SELECTED state.
if (bShapeIsSelected)
pAccessibleShape->SetState (AccessibleStateType::SELECTED);
else
pAccessibleShape->ResetState (AccessibleStateType::SELECTED);
// Does the shape have the current selection?
if (pAccessibleShape->GetState (AccessibleStateType::FOCUSED))
pCurrentlyFocusedShape = pAccessibleShape;
}
}
// Now reset and then set the FOCUSED state.
if (pCurrentlyFocusedShape != NULL)
pCurrentlyFocusedShape->ResetState (AccessibleStateType::FOCUSED);
if (pNewFocusedShape != NULL)
pNewFocusedShape->ResetState (AccessibleStateType::FOCUSED);
}
//===== AccessibleChildDescriptor ===========================================
ChildDescriptor::ChildDescriptor (const Reference<drawing::XShape>& xShape)
: mxShape (xShape),
mxAccessibleShape (NULL),
mbCreateEventPending (true)
{
// Empty.
}
ChildDescriptor::ChildDescriptor (const Reference<XAccessible>& rxAccessibleShape)
: mxShape (NULL),
mxAccessibleShape (rxAccessibleShape),
mbCreateEventPending (true)
{
// Empty.
}
AccessibleShape* ChildDescriptor::GetAccessibleShape (void) const
{
return static_cast<AccessibleShape*> (mxAccessibleShape.get());
}
/** Compare two child descriptors. Take into account that a child
descriptor may be based on a UNO shape or, already, on an accessible
shape.
*/
bool ChildDescriptor::operator == (const ChildDescriptor& aDescriptor)
{
if (mxShape == aDescriptor.mxShape)
if (mxShape.is())
return true;
else
return mxAccessibleShape == aDescriptor.mxAccessibleShape;
else
return false;
}
bool ChildDescriptor::operator < (const ChildDescriptor& aDescriptor)
{
return mxShape < aDescriptor.mxShape;
}
} // end of namespace accessibility
|