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
|
/* -*- 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 <AccessibleSmElementsControl.hxx>
#include <AccessibleSmElement.hxx>
#include <ElementsDockingWindow.hxx>
#include <smmod.hxx>
#include <comphelper/accessiblewrapper.hxx>
#include <comphelper/processfactory.hxx>
#include <comphelper/types.hxx>
#include <com/sun/star/accessibility/AccessibleEventId.hpp>
#include <com/sun/star/accessibility/AccessibleRole.hpp>
#include <com/sun/star/accessibility/AccessibleStateType.hpp>
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
#include <cppuhelper/supportsservice.hxx>
#include <cppuhelper/typeprovider.hxx>
#include <toolkit/helper/convert.hxx>
#include <unotools/accessiblerelationsethelper.hxx>
#include <unotools/accessiblestatesethelper.hxx>
#include <vcl/svapp.hxx>
#include <vcl/vclevent.hxx>
using namespace ::com::sun::star;
using namespace ::com::sun::star::accessibility;
using OContextEntryGuard = ::comphelper::OContextEntryGuard;
using OExternalLockGuard = ::comphelper::OExternalLockGuard;
// AccessibleSmElementsControl
AccessibleSmElementsControl::AccessibleSmElementsControl(SmElementsControl& rControl)
: m_pControl(&rControl)
{
}
AccessibleSmElementsControl::~AccessibleSmElementsControl() {}
void AccessibleSmElementsControl::UpdateFocus(sal_uInt16 nPos)
{
const bool bSetFocus = (nPos == SAL_MAX_UINT16);
// submit events only if the widget has the focus to avoid sending events due to mouse move
if (!m_pControl || (bSetFocus && !m_pControl->HasFocus()))
return;
if (bSetFocus)
nPos = m_pControl->itemHighlighted() - m_pControl->itemOffset();
if (nPos < m_aAccessibleChildren.size())
{
const auto& rxChild = m_aAccessibleChildren[nPos];
if (rxChild.is())
rxChild->SetFocus(bSetFocus);
}
}
void AccessibleSmElementsControl::ReleaseAllItems(bool bNotifyRemoval)
{
if (m_aAccessibleChildren.empty())
return;
m_aAccessibleChildren.clear();
if (!bNotifyRemoval)
return;
// The original toolbox accessibility code uses individual NAME_CHANGED
// events in a loop. We can't do this, because on each remove event the
// list of known children is rebuild. But since we rely on the child
// count of the SmElementsControl, we'll always have no or all items.
// In the latter case this would automatically recreate all items!
assert(m_pControl && m_pControl->itemCount() == 0);
NotifyAccessibleEvent(AccessibleEventId::INVALIDATE_ALL_CHILDREN, uno::Any(), uno::Any());
}
void AccessibleSmElementsControl::AddAllItems()
{
assert(m_pControl);
if (!m_pControl)
return;
uno::Any aNewName(getAccessibleName());
NotifyAccessibleEvent(AccessibleEventId::NAME_CHANGED, uno::Any(), aNewName);
// register the new items
sal_uInt16 nCount = getAccessibleChildCount();
for (sal_uInt16 i = 0; i < nCount; ++i)
{
uno::Any aNewValue;
aNewValue <<= getAccessibleChild(static_cast<sal_Int32>(i));
NotifyAccessibleEvent(AccessibleEventId::CHILD, uno::Any(), aNewValue);
}
}
IMPLEMENT_FORWARD_XINTERFACE2(AccessibleSmElementsControl, comphelper::OAccessibleComponentHelper,
AccessibleSmElementsControl_BASE)
IMPLEMENT_FORWARD_XTYPEPROVIDER2(AccessibleSmElementsControl,
comphelper::OAccessibleComponentHelper,
AccessibleSmElementsControl_BASE)
// XAccessible
uno::Reference<XAccessibleContext> AccessibleSmElementsControl::getAccessibleContext()
{
return this;
}
// XComponent
void AccessibleSmElementsControl::disposing()
{
comphelper::OAccessibleComponentHelper::disposing();
m_aAccessibleChildren.clear();
}
void AccessibleSmElementsControl::grabFocus()
{
SolarMutexGuard aGuard;
if (!m_pControl)
throw uno::RuntimeException();
m_pControl->GrabFocus();
}
sal_Int32 AccessibleSmElementsControl::getForeground()
{
SolarMutexGuard aGuard;
if (!m_pControl)
throw uno::RuntimeException();
return static_cast<sal_Int32>(m_pControl->GetTextColor());
}
sal_Int32 AccessibleSmElementsControl::getBackground()
{
SolarMutexGuard aGuard;
if (!m_pControl)
throw uno::RuntimeException();
Color nCol = m_pControl->GetControlBackground();
return static_cast<sal_Int32>(nCol);
}
// XServiceInfo
OUString AccessibleSmElementsControl::getImplementationName()
{
return OUString("com.sun.star.comp.toolkit.AccessibleSmElementsControl");
}
sal_Bool AccessibleSmElementsControl::supportsService(const OUString& rServiceName)
{
return cppu::supportsService(this, rServiceName);
}
uno::Sequence<OUString> AccessibleSmElementsControl::getSupportedServiceNames()
{
return { "com.sun.star.accessibility.AccessibleContext",
"com.sun.star.accessibility.AccessibleComponent",
"com.sun.star.accessibility.AccessibleSelection",
"com.sun.star.accessibility.AccessibleSmElementsControl" };
}
// XAccessibleContext
sal_Int32 AccessibleSmElementsControl::getAccessibleChildCount()
{
comphelper::OExternalLockGuard aGuard(this);
sal_Int32 nCount = 0;
if (m_pControl)
{
nCount = m_pControl->itemCount();
if (m_aAccessibleChildren.size() != sal_uInt16(nCount))
m_aAccessibleChildren.resize(nCount);
if (m_pControl->scrollbarAccessible().is())
nCount++;
}
return nCount;
}
uno::Reference<XAccessible> AccessibleSmElementsControl::getAccessibleChild(sal_Int32 i)
{
comphelper::OExternalLockGuard aGuard(this);
if (i < 0 || i >= getAccessibleChildCount())
throw lang::IndexOutOfBoundsException();
// first child may be the scrollbar
sal_uInt16 c(i);
uno::Reference<XAccessible> xScrollbar = m_pControl->scrollbarAccessible();
if (xScrollbar.is())
{
if (c == 0)
return xScrollbar;
c--;
}
assert(c < m_aAccessibleChildren.size());
rtl::Reference<AccessibleSmElement> xChild = m_aAccessibleChildren[c];
const sal_uInt16 nItemId = m_pControl->itemOffset() + c;
if (xChild.is() && xChild->itemId() != nItemId)
xChild.clear();
if (!xChild.is())
{
sal_uInt16 nHighlightItemId = m_pControl->itemHighlighted();
AccessibleSmElement* pChild = new AccessibleSmElement(m_pControl, nItemId, i);
if (pChild->itemId() == nHighlightItemId)
pChild->SetFocus(true);
m_aAccessibleChildren[c] = pChild;
xChild = pChild;
}
return xChild.get();
}
uno::Reference<XAccessible> AccessibleSmElementsControl::getAccessibleParent()
{
SolarMutexGuard aGuard;
if (!m_pControl)
throw uno::RuntimeException();
vcl::Window* pAccParent = m_pControl->GetAccessibleParentWindow();
assert(pAccParent);
return pAccParent ? pAccParent->GetAccessible() : uno::Reference<XAccessible>();
}
uno::Reference<XAccessible>
AccessibleSmElementsControl::getAccessibleAtPoint(const awt::Point& rPoint)
{
comphelper::OExternalLockGuard aGuard(this);
uno::Reference<XAccessible> xAccessible;
if (m_pControl)
{
sal_uInt16 nPos = m_pControl->itemAtPos(VCLPoint(rPoint));
nPos -= m_pControl->itemOffset();
if (nPos <= m_aAccessibleChildren.size())
xAccessible = getAccessibleChild(nPos);
}
return xAccessible;
}
sal_Int16 AccessibleSmElementsControl::getAccessibleRole() { return AccessibleRole::SCROLL_PANE; }
OUString AccessibleSmElementsControl::getAccessibleDescription() { return OUString(); }
OUString AccessibleSmElementsControl::getAccessibleName()
{
SolarMutexGuard aGuard;
OUString aName;
if (m_pControl)
aName = SmResId(m_pControl->elementSetId().getStr());
return aName;
}
// XAccessibleSelection
void AccessibleSmElementsControl::selectAccessibleChild(sal_Int32 nChildIndex)
{
OExternalLockGuard aGuard(this);
if ((!m_pControl) || nChildIndex < 0
|| static_cast<size_t>(nChildIndex) >= m_aAccessibleChildren.size())
throw lang::IndexOutOfBoundsException();
m_pControl->setItemHighlighted(nChildIndex);
}
sal_Bool AccessibleSmElementsControl::isAccessibleChildSelected(sal_Int32 nChildIndex)
{
OExternalLockGuard aGuard(this);
if ((!m_pControl) || nChildIndex < 0
|| static_cast<size_t>(nChildIndex) >= m_aAccessibleChildren.size())
throw lang::IndexOutOfBoundsException();
return (m_pControl->itemHighlighted() == nChildIndex);
}
void AccessibleSmElementsControl::clearAccessibleSelection()
{
OExternalLockGuard aGuard(this);
if (m_pControl)
m_pControl->setItemHighlighted(SAL_MAX_UINT16);
}
void AccessibleSmElementsControl::selectAllAccessibleChildren()
{
// intentionally empty
}
sal_Int32 AccessibleSmElementsControl::getSelectedAccessibleChildCount()
{
OExternalLockGuard aGuard(this);
sal_Int32 nRet = 0;
if (m_pControl
&& (m_pControl->itemHighlighted() - m_pControl->itemOffset()) < getAccessibleChildCount())
nRet = 1;
return nRet;
}
uno::Reference<XAccessible>
AccessibleSmElementsControl::getSelectedAccessibleChild(sal_Int32 nSelectedChildIndex)
{
OExternalLockGuard aGuard(this);
if (nSelectedChildIndex != 0 || !m_pControl)
throw lang::IndexOutOfBoundsException();
return getAccessibleChild(m_pControl->itemHighlighted() - m_pControl->itemOffset());
}
void AccessibleSmElementsControl::deselectAccessibleChild(sal_Int32 nChildIndex)
{
OExternalLockGuard aGuard(this);
if (nChildIndex != 0 || nChildIndex >= getAccessibleChildCount())
throw lang::IndexOutOfBoundsException();
clearAccessibleSelection(); // there can be just one selected child
}
// XAccessibleComponent
static awt::Point lcl_GetLocationOnScreen(vcl::Window const* m_pControl)
{
awt::Point aPos;
if (m_pControl)
{
tools::Rectangle aRect = m_pControl->GetWindowExtentsRelative(nullptr);
aPos.X = aRect.Left();
aPos.Y = aRect.Top();
}
return aPos;
}
static awt::Rectangle lcl_GetBounds(vcl::Window const* m_pControl)
{
// !! see VCLXAccessibleComponent::implGetBounds()
//! the coordinates returned are relative to the parent window !
//! Thus the top-left point may be different from (0, 0) !
awt::Rectangle aBounds;
if (m_pControl)
{
tools::Rectangle aRect = m_pControl->GetWindowExtentsRelative(nullptr);
aBounds.X = aRect.Left();
aBounds.Y = aRect.Top();
aBounds.Width = aRect.GetWidth();
aBounds.Height = aRect.GetHeight();
vcl::Window* pParent = m_pControl->GetAccessibleParentWindow();
if (pParent)
{
tools::Rectangle aParentRect = pParent->GetWindowExtentsRelative(nullptr);
awt::Point aParentScreenLoc(aParentRect.Left(), aParentRect.Top());
aBounds.X -= aParentScreenLoc.X;
aBounds.Y -= aParentScreenLoc.Y;
}
}
return aBounds;
}
void AccessibleSmElementsControl::TestControl()
{
if (!m_pControl)
throw uno::RuntimeException();
assert(m_pControl->GetParent()->GetAccessible() == getAccessibleParent());
}
awt::Rectangle AccessibleSmElementsControl::implGetBounds()
{
SolarMutexGuard aGuard;
TestControl();
return lcl_GetBounds(m_pControl);
}
awt::Rectangle AccessibleSmElementsControl::getBounds() { return implGetBounds(); }
sal_Bool AccessibleSmElementsControl::containsPoint(const awt::Point& aPoint)
{
SolarMutexGuard aGuard;
TestControl();
Size aSz(m_pControl->GetSizePixel());
return aPoint.X >= 0 && aPoint.Y >= 0 && aPoint.X < aSz.Width() && aPoint.Y < aSz.Height();
}
awt::Point AccessibleSmElementsControl::getLocation()
{
SolarMutexGuard aGuard;
TestControl();
awt::Rectangle aRect(lcl_GetBounds(m_pControl));
return awt::Point(aRect.X, aRect.Y);
}
awt::Point AccessibleSmElementsControl::getLocationOnScreen()
{
SolarMutexGuard aGuard;
TestControl();
return lcl_GetLocationOnScreen(m_pControl);
}
awt::Size AccessibleSmElementsControl::getSize()
{
SolarMutexGuard aGuard;
TestControl();
Size aSz(m_pControl->GetSizePixel());
#if OSL_DEBUG_LEVEL > 0 && !defined NDEBUG
awt::Rectangle aRect(lcl_GetBounds(m_pControl));
Size aSz2(aRect.Width, aRect.Height);
assert(aSz == aSz2 && "mismatch in width");
#endif
return awt::Size(aSz.Width(), aSz.Height());
}
uno::Reference<XAccessibleRelationSet> AccessibleSmElementsControl::getAccessibleRelationSet()
{
uno::Reference<XAccessibleRelationSet> xRelSet = new utl::AccessibleRelationSetHelper();
return xRelSet; // empty relation set
}
uno::Reference<XAccessibleStateSet> AccessibleSmElementsControl::getAccessibleStateSet()
{
SolarMutexGuard aGuard;
::utl::AccessibleStateSetHelper* pStateSet = new ::utl::AccessibleStateSetHelper;
uno::Reference<XAccessibleStateSet> xStateSet(pStateSet);
if (!m_pControl)
pStateSet->AddState(AccessibleStateType::DEFUNC);
else
{
pStateSet->AddState(AccessibleStateType::ENABLED);
pStateSet->AddState(AccessibleStateType::FOCUSABLE);
if (m_pControl->HasFocus())
pStateSet->AddState(AccessibleStateType::FOCUSED);
if (m_pControl->IsActive())
pStateSet->AddState(AccessibleStateType::ACTIVE);
if (m_pControl->IsVisible())
pStateSet->AddState(AccessibleStateType::SHOWING);
if (m_pControl->IsReallyVisible())
pStateSet->AddState(AccessibleStateType::VISIBLE);
if (COL_TRANSPARENT != m_pControl->GetBackground().GetColor())
pStateSet->AddState(AccessibleStateType::OPAQUE);
}
return xStateSet;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|