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
|
/* -*- 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 <accessiblecell.hxx>
#include "svx/DescriptionGenerator.hxx"
#include <com/sun/star/accessibility/AccessibleRole.hpp>
#include <com/sun/star/accessibility/AccessibleStateType.hpp>
#include <vcl/svapp.hxx>
#include <unotools/accessiblestatesethelper.hxx>
#include <comphelper/string.hxx>
#include <editeng/outlobj.hxx>
#include <svx/unoshtxt.hxx>
#include <svx/svdotext.hxx>
using namespace ::sdr::table;
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::accessibility;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::container;
namespace accessibility {
// AccessibleCell
AccessibleCell::AccessibleCell( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible>& rxParent, const sdr::table::CellRef& rCell, sal_Int32 nIndex, const AccessibleShapeTreeInfo& rShapeTreeInfo )
: AccessibleCellBase( rxParent, AccessibleRole::TABLE_CELL )
, maShapeTreeInfo( rShapeTreeInfo )
, mnIndexInParent( nIndex )
, mpText( NULL )
, mxCell( rCell )
{
//Init the pAccTable var
pAccTable = dynamic_cast <AccessibleTableShape *> (rxParent.get());
}
AccessibleCell::~AccessibleCell (void)
{
DBG_ASSERT( mpText == 0, "svx::AccessibleCell::~AccessibleCell(), not disposed!?" );
}
void AccessibleCell::Init (void)
{
SdrView* pView = maShapeTreeInfo.GetSdrView();
const Window* pWindow = maShapeTreeInfo.GetWindow ();
if( (pView != NULL) && (pWindow != NULL) && mxCell.is())
{
OutlinerParaObject* pOutlinerParaObject = mxCell->GetEditOutlinerParaObject(); // Get the OutlinerParaObject if text edit is active
bool bOwnParaObject = pOutlinerParaObject != 0;
if( !pOutlinerParaObject )
pOutlinerParaObject = mxCell->GetOutlinerParaObject();
// create AccessibleTextHelper to handle this shape's text
if( pOutlinerParaObject )
{
// non-empty text -> use full-fledged edit source right away
SAL_WNODEPRECATED_DECLARATIONS_PUSH
::std::auto_ptr<SvxEditSource> pEditSource( new SvxTextEditSource( mxCell->GetObject(), mxCell.get(), *pView, *pWindow) );
SAL_WNODEPRECATED_DECLARATIONS_POP
mpText = new AccessibleTextHelper( pEditSource );
mpText->SetEventSource(this);
}
if( bOwnParaObject)
delete pOutlinerParaObject;
}
}
bool AccessibleCell::SetState (sal_Int16 aState)
{
bool bStateHasChanged = false;
if (aState == AccessibleStateType::FOCUSED && mpText != NULL)
{
// Offer FOCUSED state to edit engine and detect whether the state
// changes.
sal_Bool bIsFocused = mpText->HaveFocus ();
mpText->SetFocus (sal_True);
bStateHasChanged = (bIsFocused != mpText->HaveFocus ());
}
else
bStateHasChanged = AccessibleContextBase::SetState (aState);
return bStateHasChanged;
}
bool AccessibleCell::ResetState (sal_Int16 aState)
{
bool bStateHasChanged = false;
if (aState == AccessibleStateType::FOCUSED && mpText != NULL)
{
// Try to remove FOCUSED state from the edit engine and detect
// whether the state changes.
sal_Bool bIsFocused = mpText->HaveFocus ();
mpText->SetFocus (sal_False);
bStateHasChanged = (bIsFocused != mpText->HaveFocus ());
}
else
bStateHasChanged = AccessibleContextBase::ResetState (aState);
return bStateHasChanged;
}
bool AccessibleCell::operator== (const AccessibleCell& rAccessibleCell)
{
return this == &rAccessibleCell;
}
// XInterface
Any SAL_CALL AccessibleCell::queryInterface( const Type& aType ) throw (RuntimeException, std::exception)
{
return AccessibleCellBase::queryInterface( aType );
}
void SAL_CALL AccessibleCell::acquire( ) throw ()
{
AccessibleCellBase::acquire();
}
void SAL_CALL AccessibleCell::release( ) throw ()
{
AccessibleCellBase::release();
}
// XAccessibleContext
/** The children of this cell come from the paragraphs of text.
*/
sal_Int32 SAL_CALL AccessibleCell::getAccessibleChildCount() throw (::com::sun::star::uno::RuntimeException, std::exception)
{
SolarMutexGuard aSolarGuard;
ThrowIfDisposed ();
return mpText != NULL ? mpText->GetChildCount () : 0;
}
/** Forward the request to the shape. Return the requested shape or throw
an exception for a wrong index.
*/
Reference<XAccessible> SAL_CALL AccessibleCell::getAccessibleChild (sal_Int32 nIndex) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
{
SolarMutexGuard aSolarGuard;
ThrowIfDisposed ();
// todo: does GetChild throw IndexOutOfBoundsException?
return mpText->GetChild (nIndex);
}
/** Return a copy of the state set.
Possible states are:
ENABLED
SHOWING
VISIBLE
*/
Reference<XAccessibleStateSet> SAL_CALL AccessibleCell::getAccessibleStateSet (void) throw (RuntimeException, std::exception)
{
SolarMutexGuard aSolarGuard;
::osl::MutexGuard aGuard (maMutex);
Reference<XAccessibleStateSet> xStateSet;
if (rBHelper.bDisposed || mpText == NULL)
{
// Return a minimal state set that only contains the DEFUNC state.
xStateSet = AccessibleContextBase::getAccessibleStateSet ();
}
else
{
::utl::AccessibleStateSetHelper* pStateSet = static_cast< ::utl::AccessibleStateSetHelper*>(mxStateSet.get());
if(pStateSet)
{
// Merge current FOCUSED state from edit engine.
if (mpText != NULL)
{
if (mpText->HaveFocus())
pStateSet->AddState (AccessibleStateType::FOCUSED);
else
pStateSet->RemoveState (AccessibleStateType::FOCUSED);
}
// Set the invisible state for merged cell
if (mxCell.is() && mxCell->isMerged())
pStateSet->RemoveState(AccessibleStateType::VISIBLE);
else
pStateSet->AddState(AccessibleStateType::VISIBLE);
//Just when the parent table is not read-only,set states EDITABLE,RESIZABLE,MOVEABLE
::com::sun::star::uno::Reference<XAccessible> xTempAcc = getAccessibleParent();
if( xTempAcc.is() )
{
::com::sun::star::uno::Reference<XAccessibleContext>
xTempAccContext = xTempAcc->getAccessibleContext();
if( xTempAccContext.is() )
{
::com::sun::star::uno::Reference<XAccessibleStateSet> rState =
xTempAccContext->getAccessibleStateSet();
if( rState.is() ) {
com::sun::star::uno::Sequence<short> pStates = rState->getStates();
int count = pStates.getLength();
for( int iIndex = 0;iIndex < count;iIndex++ )
{
if( pStates[iIndex] == AccessibleStateType::EDITABLE )
{
pStateSet->AddState (AccessibleStateType::EDITABLE);
pStateSet->AddState (AccessibleStateType::RESIZABLE);
pStateSet->AddState (AccessibleStateType::MOVEABLE);
break;
}
}
}
}
}
// Create a copy of the state set that may be modified by the
// caller without affecting the current state set.
xStateSet = Reference<XAccessibleStateSet>(new ::utl::AccessibleStateSetHelper (*pStateSet));
}
}
return xStateSet;
}
// XAccessibleComponent
sal_Bool SAL_CALL AccessibleCell::containsPoint( const ::com::sun::star::awt::Point& aPoint) throw (::com::sun::star::uno::RuntimeException, std::exception)
{
return AccessibleComponentBase::containsPoint( aPoint );
}
/** The implementation below is at the moment straightforward. It iterates
over all children (and thereby instances all children which have not
been already instatiated) until a child covering the specifed point is
found.
This leaves room for improvement. For instance, first iterate only over
the already instantiated children and only if no match is found
instantiate the remaining ones.
*/
Reference<XAccessible > SAL_CALL AccessibleCell::getAccessibleAtPoint ( const ::com::sun::star::awt::Point& aPoint) throw(RuntimeException, std::exception)
{
SolarMutexGuard aSolarGuard;
::osl::MutexGuard aGuard (maMutex);
sal_Int32 nChildCount = getAccessibleChildCount ();
for (sal_Int32 i=0; i<nChildCount; ++i)
{
Reference<XAccessible> xChild (getAccessibleChild (i));
if (xChild.is())
{
Reference<XAccessibleComponent> xChildComponent (xChild->getAccessibleContext(), uno::UNO_QUERY);
if (xChildComponent.is())
{
awt::Rectangle aBBox (xChildComponent->getBounds());
if ( (aPoint.X >= aBBox.X)
&& (aPoint.Y >= aBBox.Y)
&& (aPoint.X < aBBox.X+aBBox.Width)
&& (aPoint.Y < aBBox.Y+aBBox.Height) )
return xChild;
}
}
}
// Have not found a child under the given point. Returning empty
// reference to indicate this.
return uno::Reference<XAccessible>();
}
::com::sun::star::awt::Rectangle SAL_CALL AccessibleCell::getBounds(void) throw(RuntimeException, std::exception)
{
SolarMutexGuard aSolarGuard;
::osl::MutexGuard aGuard (maMutex);
ThrowIfDisposed ();
::com::sun::star::awt::Rectangle aBoundingBox;
if( mxCell.is() )
{
// Get the cell's bounding box in internal coordinates (in 100th of mm)
const ::Rectangle aCellRect( mxCell->getCellRect() );
// Transform coordinates from internal to pixel.
if (maShapeTreeInfo.GetViewForwarder() == NULL)
throw uno::RuntimeException ("AccessibleCell has no valid view forwarder",static_cast<uno::XWeak*>(this));
::Size aPixelSize( maShapeTreeInfo.GetViewForwarder()->LogicToPixel(::Size(aCellRect.GetWidth(), aCellRect.GetHeight())) );
::Point aPixelPosition( maShapeTreeInfo.GetViewForwarder()->LogicToPixel( aCellRect.TopLeft() ));
// Clip the shape's bounding box with the bounding box of its parent.
Reference<XAccessibleComponent> xParentComponent ( getAccessibleParent(), uno::UNO_QUERY);
if (xParentComponent.is())
{
// Make the coordinates relative to the parent.
awt::Point aParentLocation (xParentComponent->getLocationOnScreen());
int x = aPixelPosition.getX() - aParentLocation.X;
int y = aPixelPosition.getY() - aParentLocation.Y;
// Clip with parent (with coordinates relative to itself).
::Rectangle aBBox ( x, y, x + aPixelSize.getWidth(), y + aPixelSize.getHeight());
awt::Size aParentSize (xParentComponent->getSize());
::Rectangle aParentBBox (0,0, aParentSize.Width, aParentSize.Height);
aBBox = aBBox.GetIntersection (aParentBBox);
aBoundingBox = awt::Rectangle ( aBBox.getX(), aBBox.getY(), aBBox.getWidth(), aBBox.getHeight());
}
else
{
OSL_TRACE ("parent does not support component");
aBoundingBox = awt::Rectangle (aPixelPosition.getX(), aPixelPosition.getY(),aPixelSize.getWidth(), aPixelSize.getHeight());
}
}
return aBoundingBox;
}
::com::sun::star::awt::Point SAL_CALL AccessibleCell::getLocation(void) throw (RuntimeException, std::exception)
{
ThrowIfDisposed ();
::com::sun::star::awt::Rectangle aBoundingBox(getBounds());
return ::com::sun::star::awt::Point(aBoundingBox.X, aBoundingBox.Y);
}
::com::sun::star::awt::Point SAL_CALL AccessibleCell::getLocationOnScreen(void) throw(RuntimeException, std::exception)
{
ThrowIfDisposed ();
// Get relative position...
::com::sun::star::awt::Point aLocation(getLocation ());
// ... and add absolute position of the parent.
Reference<XAccessibleComponent> xParentComponent( getAccessibleParent(), uno::UNO_QUERY);
if(xParentComponent.is())
{
::com::sun::star::awt::Point aParentLocation(xParentComponent->getLocationOnScreen());
aLocation.X += aParentLocation.X;
aLocation.Y += aParentLocation.Y;
}
else
{
OSL_TRACE ("getLocation: parent does not support XAccessibleComponent");
}
return aLocation;
}
awt::Size SAL_CALL AccessibleCell::getSize (void) throw (RuntimeException, std::exception)
{
ThrowIfDisposed ();
awt::Rectangle aBoundingBox (getBounds());
return awt::Size (aBoundingBox.Width, aBoundingBox.Height);
}
void SAL_CALL AccessibleCell::addFocusListener ( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFocusListener >& xListener) throw (::com::sun::star::uno::RuntimeException)
{
AccessibleComponentBase::addFocusListener( xListener );
}
void SAL_CALL AccessibleCell::removeFocusListener (const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFocusListener >& xListener ) throw (::com::sun::star::uno::RuntimeException)
{
AccessibleComponentBase::removeFocusListener( xListener );
}
void SAL_CALL AccessibleCell::grabFocus (void) throw (::com::sun::star::uno::RuntimeException, std::exception)
{
AccessibleComponentBase::grabFocus();
}
sal_Int32 SAL_CALL AccessibleCell::getForeground(void) throw (RuntimeException, std::exception)
{
ThrowIfDisposed ();
sal_Int32 nColor (0x0ffffffL);
// todo
return nColor;
}
sal_Int32 SAL_CALL AccessibleCell::getBackground (void) throw (RuntimeException, std::exception)
{
ThrowIfDisposed ();
sal_Int32 nColor (0L);
// todo
return nColor;
}
// XAccessibleExtendedComponent
::com::sun::star::uno::Reference< ::com::sun::star::awt::XFont > SAL_CALL AccessibleCell::getFont (void) throw (::com::sun::star::uno::RuntimeException, std::exception)
{
//todo
return AccessibleComponentBase::getFont();
}
OUString SAL_CALL AccessibleCell::getTitledBorderText (void) throw (::com::sun::star::uno::RuntimeException, std::exception)
{
return AccessibleComponentBase::getTitledBorderText();
}
OUString SAL_CALL AccessibleCell::getToolTipText (void) throw (::com::sun::star::uno::RuntimeException, std::exception)
{
return AccessibleComponentBase::getToolTipText();
}
// XAccessibleEventBroadcaster
void SAL_CALL AccessibleCell::addAccessibleEventListener( const Reference<XAccessibleEventListener >& rxListener) throw (RuntimeException, std::exception)
{
SolarMutexGuard aSolarGuard;
::osl::MutexGuard aGuard (maMutex);
if (rBHelper.bDisposed || rBHelper.bInDispose)
{
Reference<XInterface> xSource( static_cast<XComponent *>(this) );
lang::EventObject aEventObj(xSource);
rxListener->disposing(aEventObj);
}
else
{
AccessibleContextBase::addAccessibleEventListener (rxListener);
if (mpText != NULL)
mpText->AddEventListener (rxListener);
}
}
void SAL_CALL AccessibleCell::removeAccessibleEventListener( const Reference<XAccessibleEventListener >& rxListener) throw (RuntimeException, std::exception)
{
SolarMutexGuard aSolarGuard;
AccessibleContextBase::removeAccessibleEventListener(rxListener);
if (mpText != NULL)
mpText->RemoveEventListener (rxListener);
}
// XServiceInfo
OUString SAL_CALL AccessibleCell::getImplementationName(void) throw (RuntimeException, std::exception)
{
return OUString("AccessibleCell");
}
Sequence<OUString> SAL_CALL AccessibleCell::getSupportedServiceNames(void) throw (RuntimeException, std::exception)
{
ThrowIfDisposed ();
// Get list of supported service names from base class...
uno::Sequence<OUString> aServiceNames = AccessibleContextBase::getSupportedServiceNames();
sal_Int32 nCount (aServiceNames.getLength());
// ...and add additional names.
aServiceNames.realloc (nCount + 1);
static const OUString sAdditionalServiceName ("com.sun.star.drawing.AccessibleCell");
aServiceNames[nCount] = sAdditionalServiceName;
return aServiceNames;
}
// IAccessibleViewForwarderListener
void AccessibleCell::ViewForwarderChanged (ChangeType /*aChangeType*/, const IAccessibleViewForwarder* /*pViewForwarder*/)
{
// Inform all listeners that the graphical representation (i.e. size
// and/or position) of the shape has changed.
CommitChange(AccessibleEventId::VISIBLE_DATA_CHANGED, Any(), Any());
// update our children that our screen position might have changed
if( mpText )
mpText->UpdateChildren();
}
// protected
void AccessibleCell::disposing (void)
{
SolarMutexGuard aSolarGuard;
::osl::MutexGuard aGuard (maMutex);
// Make sure to send an event that this object looses the focus in the
// case that it has the focus.
::utl::AccessibleStateSetHelper* pStateSet = static_cast< ::utl::AccessibleStateSetHelper*>(mxStateSet.get());
if (pStateSet != NULL)
pStateSet->RemoveState(AccessibleStateType::FOCUSED);
if (mpText != NULL)
{
mpText->Dispose();
delete mpText;
mpText = NULL;
}
// Cleanup. Remove references to objects to allow them to be
// destroyed.
mxCell.clear();
maShapeTreeInfo = AccessibleShapeTreeInfo();
// Call base classes.
AccessibleContextBase::dispose ();
}
sal_Int32 SAL_CALL AccessibleCell::getAccessibleIndexInParent (void) throw (RuntimeException, std::exception)
{
ThrowIfDisposed ();
return mnIndexInParent;
}
sdr::table::CellRef AccessibleCell::getCellRef()
{
return mxCell;
}
OUString AccessibleCell::getCellName( sal_Int32 nCol, sal_Int32 nRow )
{
OUStringBuffer aBuf;
if (nCol < 26*26)
{
if (nCol < 26)
aBuf.append( static_cast<sal_Unicode>( 'A' +
static_cast<sal_uInt16>(nCol)));
else
{
aBuf.append( static_cast<sal_Unicode>( 'A' +
(static_cast<sal_uInt16>(nCol) / 26) - 1));
aBuf.append( static_cast<sal_Unicode>( 'A' +
(static_cast<sal_uInt16>(nCol) % 26)));
}
}
else
{
OUStringBuffer aStr;
while (nCol >= 26)
{
sal_Int32 nC = nCol % 26;
aStr.append(static_cast<sal_Unicode>( 'A' +
static_cast<sal_uInt16>(nC)));
nCol = nCol - nC;
nCol = nCol / 26 - 1;
}
aStr.append(static_cast<sal_Unicode>( 'A' +
static_cast<sal_uInt16>(nCol)));
aBuf.append(comphelper::string::reverseString(aStr.makeStringAndClear()));
}
aBuf.append( OUString::number(nRow+1) );
return aBuf.makeStringAndClear();
}
OUString SAL_CALL AccessibleCell::getAccessibleName (void) throw (::com::sun::star::uno::RuntimeException, std::exception)
{
ThrowIfDisposed ();
SolarMutexGuard aSolarGuard;
if( pAccTable )
{
try
{
sal_Int32 nRow = 0, nCol = 0;
pAccTable->getColumnAndRow(mnIndexInParent, nCol, nRow);
return getCellName( nCol, nRow );
}
catch(const Exception&)
{
}
}
return AccessibleCellBase::getAccessibleName();
}
void AccessibleCell::UpdateChildren()
{
if (mpText)
mpText->UpdateChildren();
}
/* MT: Above getAccessibleName was introduced with IA2 CWS, while below was introduce in 3.3 meanwhile. Check which one is correct
+If this is correct, we also don't need sdr::table::CellRef getCellRef(), UpdateChildren(), getCellName( sal_Int32 nCol, sal_Int32 nRow ) above
+
OUString SAL_CALL AccessibleCell::getAccessibleName (void) throw (::com::sun::star::uno::RuntimeException)
{
ThrowIfDisposed ();
SolarMutexGuard aSolarGuard;
if( mxCell.is() )
return mxCell->getName();
return AccessibleCellBase::getAccessibleName();
}
*/
} // end of namespace accessibility
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|