1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the accessibility module of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
29
#include "qaccessiblecompat.h"
30
#include "q3widgetstack.h"
32
#include <q3listview.h>
33
#include <q3textedit.h>
34
#include <q3iconview.h>
35
#include <q3listbox.h>
38
\fn Q3AccessibleScrollView::Q3AccessibleScrollView(QWidget* widget, Role role)
40
Constructs a Q3AccessibleScrollView object for a \a widget.
41
The \a role is propagated to the QAccessibleWidget constructor.
43
Q3AccessibleScrollView::Q3AccessibleScrollView(QWidget *w, Role role)
44
: QAccessibleWidget(w, role)
49
Returns the ID of the item at viewport position \a x, \a y.
51
int Q3AccessibleScrollView::itemAt(int /*x*/, int /*y*/) const
57
Returns the location in viewport coordinates of the item with ID \a
60
QRect Q3AccessibleScrollView::itemRect(int /*item*/) const
66
Returns the number of items in the scroll view.
68
int Q3AccessibleScrollView::itemCount() const
74
\class QAccessibleListView qaccessiblewidget.h
75
\brief The QAccessibleListView class implements the QAccessibleInterface for list views.
79
static Q3ListViewItem *findLVItem(Q3ListView* listView, int child)
82
Q3ListViewItemIterator it(listView);
83
Q3ListViewItem *item = it.current();
84
while (item && id < child) {
93
\fn QAccessibleListView::QAccessibleListView(QWidget* widget)
95
Constructs a QAccessibleListView object for a \a widget.
97
QAccessibleListView::QAccessibleListView(QWidget *o)
98
: Q3AccessibleScrollView(o, Tree)
102
/*! Returns the list view. */
103
Q3ListView *QAccessibleListView::listView() const
105
Q_ASSERT(widget()->inherits("Q3ListView"));
106
return (Q3ListView*)widget();
110
int QAccessibleListView::itemAt(int x, int y) const
112
Q3ListViewItem *item = listView()->itemAt(QPoint(x, y));
116
Q3ListViewItemIterator it(listView());
118
while (it.current()) {
119
if (it.current() == item)
128
QRect QAccessibleListView::itemRect(int child) const
130
Q3ListViewItem *item = findLVItem(listView(), child);
133
return listView()->itemRect(item);
137
int QAccessibleListView::itemCount() const
139
Q3ListViewItemIterator it(listView());
141
while (it.current()) {
150
QString QAccessibleListView::text(Text t, int child) const
152
if (!child || t != Name)
153
return Q3AccessibleScrollView::text(t, child);
155
Q3ListViewItem *item = findLVItem(listView(), child);
158
return item->text(0);
162
QAccessible::Role QAccessibleListView::role(int child) const
165
return Q3AccessibleScrollView::role(child);
170
QAccessible::State QAccessibleListView::state(int child) const
172
State state = Q3AccessibleScrollView::state(child);
173
Q3ListViewItem *item;
174
if (!child || !(item = findLVItem(listView(), child)))
177
if (item->isSelectable()) {
178
if (listView()->selectionMode() == Q3ListView::Multi)
179
state |= MultiSelectable;
180
else if (listView()->selectionMode() == Q3ListView::Extended)
181
state |= ExtSelectable;
182
else if (listView()->selectionMode() == Q3ListView::Single)
184
if (item->isSelected())
187
if (listView()->focusPolicy() != Qt::NoFocus) {
189
if (item == listView()->currentItem())
192
if (item->childCount()) {
198
if (!listView()->itemRect(item).isValid())
201
if (item->rtti() == Q3CheckListItem::RTTI) {
202
if (((Q3CheckListItem*)item)->isOn())
209
QAccessibleInterface *QAccessibleListView::focusChild(int *child) const
211
Q3ListViewItem *item = listView()->currentItem();
215
Q3ListViewItemIterator it(listView());
217
while (it.current()) {
218
if (it.current() == item) {
220
return (QAccessibleInterface*)this;
229
bool QAccessibleListView::setFocus(int child)
231
bool res = Q3AccessibleScrollView::setFocus(0);
235
Q3ListViewItem *item = findLVItem(listView(), child);
238
listView()->setCurrentItem(item);
243
bool QAccessibleListView::setSelected(int child, bool on, bool extend)
245
if (!child || (extend &&
246
listView()->selectionMode() != Q3ListView::Extended &&
247
listView()->selectionMode() != Q3ListView::Multi))
250
Q3ListViewItem *item = findLVItem(listView(), child);
254
listView()->setSelected(item, on);
256
Q3ListViewItem *current = listView()->currentItem();
259
bool down = item->itemPos() > current->itemPos();
260
Q3ListViewItemIterator it(current);
261
while (it.current()) {
262
listView()->setSelected(it.current(), on);
263
if (it.current() == item)
275
void QAccessibleListView::clearSelection()
277
listView()->clearSelection();
281
QVector<int> QAccessibleListView::selection() const
287
Q3ListViewItemIterator it(listView());
288
while (it.current()) {
289
if (it.current()->isSelected()) {
292
array[(int)size-1] = id;
301
\class QAccessibleIconView qaccessiblewidget.h
302
\brief The QAccessibleIconView class implements the QAccessibleInterface for icon views.
306
static Q3IconViewItem *findIVItem(Q3IconView *iconView, int child)
309
Q3IconViewItem *item = iconView->firstItem();
310
while (item && id < child) {
311
item = item->nextItem();
319
\fn QAccessibleIconView::QAccessibleIconView(QWidget* widget)
321
Constructs a QAccessibleIconView object for a \a widget.
323
QAccessibleIconView::QAccessibleIconView(QWidget *o)
324
: Q3AccessibleScrollView(o, List)
326
Q_ASSERT(widget()->inherits("Q3IconView"));
329
/*! Returns the icon view. */
330
Q3IconView *QAccessibleIconView::iconView() const
332
return (Q3IconView*)widget();
336
int QAccessibleIconView::itemAt(int x, int y) const
338
Q3IconViewItem *item = iconView()->findItem(QPoint(x, y));
339
return iconView()->index(item) + 1;
343
QRect QAccessibleIconView::itemRect(int child) const
345
Q3IconViewItem *item = findIVItem(iconView(), child);
353
int QAccessibleIconView::itemCount() const
355
return iconView()->count();
359
QString QAccessibleIconView::text(Text t, int child) const
361
if (!child || t != Name)
362
return Q3AccessibleScrollView::text(t, child);
364
Q3IconViewItem *item = findIVItem(iconView(), child);
371
QAccessible::Role QAccessibleIconView::role(int child) const
374
return Q3AccessibleScrollView::role(child);
379
QAccessible::State QAccessibleIconView::state(int child) const
381
State state = Q3AccessibleScrollView::state(child);
382
Q3IconViewItem *item;
383
if (!child || !(item = findIVItem(iconView(), child)))
386
if (item->isSelectable()) {
387
if (iconView()->selectionMode() == Q3IconView::Multi)
388
state |= MultiSelectable;
389
else if (iconView()->selectionMode() == Q3IconView::Extended)
390
state |= ExtSelectable;
391
else if (iconView()->selectionMode() == Q3IconView::Single)
393
if (item->isSelected())
396
if (iconView()->itemsMovable())
398
if (iconView()->focusPolicy() != Qt::NoFocus) {
400
if (item == iconView()->currentItem())
408
QAccessibleInterface *QAccessibleIconView::focusChild(int *child) const
410
Q3IconViewItem *item = iconView()->currentItem();
414
*child = iconView()->index(item);
415
return (QAccessibleInterface*)this;
419
bool QAccessibleIconView::setFocus(int child)
421
bool res = Q3AccessibleScrollView::setFocus(0);
425
Q3IconViewItem *item = findIVItem(iconView(), child);
428
iconView()->setCurrentItem(item);
433
bool QAccessibleIconView::setSelected(int child, bool on, bool extend)
435
if (!child || (extend &&
436
iconView()->selectionMode() != Q3IconView::Extended &&
437
iconView()->selectionMode() != Q3IconView::Multi))
440
Q3IconViewItem *item = findIVItem(iconView(), child);
444
iconView()->setSelected(item, on, true);
446
Q3IconViewItem *current = iconView()->currentItem();
450
Q3IconViewItem *temp = current;
451
while ((temp = temp->nextItem())) {
459
while ((temp = temp->nextItem())) {
460
iconView()->setSelected(temp, on, true);
465
while ((temp = temp->prevItem())) {
466
iconView()->setSelected(temp, on, true);
476
void QAccessibleIconView::clearSelection()
478
iconView()->clearSelection();
482
QVector<int> QAccessibleIconView::selection() const
487
array.resize(iconView()->count());
488
Q3IconViewItem *item = iconView()->firstItem();
490
if (item->isSelected()) {
492
array[(int)size-1] = id;
494
item = item->nextItem();
503
\class QAccessibleTextEdit qaccessiblewidget.h
504
\brief The QAccessibleTextEdit class implements the QAccessibleInterface for richtext editors.
509
\fn QAccessibleTextEdit::QAccessibleTextEdit(QWidget* widget)
511
Constructs a QAccessibleTextEdit object for a \a widget.
513
QAccessibleTextEdit::QAccessibleTextEdit(QWidget *o)
514
: Q3AccessibleScrollView(o, Pane)
516
Q_ASSERT(widget()->inherits("Q3TextEdit"));
519
/*! Returns the text edit. */
520
Q3TextEdit *QAccessibleTextEdit::textEdit() const
523
return (Q3TextEdit*)widget();
527
int QAccessibleTextEdit::itemAt(int x, int y) const
530
QPoint cp = textEdit()->viewportToContents(QPoint(x,y));
531
textEdit()->charAt(cp , &p);
536
QRect QAccessibleTextEdit::itemRect(int item) const
538
QRect rect = textEdit()->paragraphRect(item - 1);
541
QPoint ntl = textEdit()->contentsToViewport(QPoint(rect.x(), rect.y()));
542
return QRect(ntl.x(), ntl.y(), rect.width(), rect.height());
546
int QAccessibleTextEdit::itemCount() const
548
return textEdit()->paragraphs();
552
QString QAccessibleTextEdit::text(Text t, int child) const
554
if (t == Name && child > 0)
555
return textEdit()->text(child - 1);
558
return textEdit()->text(child - 1);
560
return textEdit()->text();
563
return Q3AccessibleScrollView::text(t, child);
567
void QAccessibleTextEdit::setText(Text t, int control, const QString &text)
569
if (t != Value || control) {
570
Q3AccessibleScrollView::setText(t, control, text);
573
textEdit()->setText(text);
577
QAccessible::Role QAccessibleTextEdit::role(int child) const
581
return Q3AccessibleScrollView::role(child);
585
\class QAccessibleWidgetStack qaccessible.h
586
\brief The QAccessibleWidgetStack class implements the QAccessibleInterface for widget stacks.
588
\ingroup accessibility
593
\fn QAccessibleWidgetStack::QAccessibleWidgetStack(QWidget* widget)
595
Creates a QAccessibleWidgetStack object for a \a widget.
597
QAccessibleWidgetStack::QAccessibleWidgetStack(QWidget *w)
598
: QAccessibleWidget(w, LayeredPane)
600
Q_ASSERT(widgetStack());
601
setDescription("This is a widgetstack");
604
/*! Returns the widget stack. */
605
Q3WidgetStack *QAccessibleWidgetStack::widgetStack() const
607
return qobject_cast<Q3WidgetStack*>(object());
611
int QAccessibleWidgetStack::childCount() const
613
// a widget stack has always only one accessible widget
618
int QAccessibleWidgetStack::indexOfChild(const QAccessibleInterface *child) const
620
QObject *childObject = child ? child->object() : 0;
621
if (childObject != widgetStack()->visibleWidget())
627
int QAccessibleWidgetStack::childAt(int, int) const
629
QWidget *curPage = widgetStack()->visibleWidget();
636
int QAccessibleWidgetStack::navigate(RelationFlag rel, int entry,
637
QAccessibleInterface **target) const
640
QObject *targetObject = 0;
646
targetObject = widgetStack()->visibleWidget();
649
return QAccessibleWidget::navigate(rel, entry, target);
651
*target = QAccessible::queryAccessibleInterface(targetObject);
652
return *target ? 0 : -1;
656
\class QAccessibleListBox qaccessiblewidget.h
657
\brief The QAccessibleListBox class implements the QAccessibleInterface for list boxes.
659
\ingroup accessibility
664
\fn QAccessibleListBox::QAccessibleListBox(QWidget* widget)
666
Constructs a QAccessibleListBox object for a \a widget.
668
QAccessibleListBox::QAccessibleListBox(QWidget *o)
669
: Q3AccessibleScrollView(o, List)
671
Q_ASSERT(widget()->inherits("Q3ListBox"));
674
/*! Returns the list box. */
675
Q3ListBox *QAccessibleListBox::listBox() const
677
return (Q3ListBox*)widget();
681
int QAccessibleListBox::itemAt(int x, int y) const
683
Q3ListBoxItem *item = listBox()->itemAt(QPoint(x, y));
684
return listBox()->index(item) + 1;
688
QRect QAccessibleListBox::itemRect(int item) const
690
return listBox()->itemRect(listBox()->item(item-1));
694
int QAccessibleListBox::itemCount() const
696
return listBox()->count();
700
QString QAccessibleListBox::text(Text t, int child) const
702
if (!child || t != Name)
703
return Q3AccessibleScrollView::text(t, child);
705
Q3ListBoxItem *item = listBox()->item(child - 1);
712
QAccessible::Role QAccessibleListBox::role(int child) const
715
return Q3AccessibleScrollView::role(child);
720
QAccessible::State QAccessibleListBox::state(int child) const
722
State state = Q3AccessibleScrollView::state(child);
724
if (!child || !(item = listBox()->item(child - 1)))
727
if (item->isSelectable()) {
728
if (listBox()->selectionMode() == Q3ListBox::Multi)
729
state |= MultiSelectable;
730
else if (listBox()->selectionMode() == Q3ListBox::Extended)
731
state |= ExtSelectable;
732
else if (listBox()->selectionMode() == Q3ListBox::Single)
734
if (item->isSelected())
737
if (listBox()->focusPolicy() != Qt::NoFocus) {
739
if (item->isCurrent())
742
if (!listBox()->itemVisible(item))
749
bool QAccessibleListBox::setFocus(int child)
751
bool res = Q3AccessibleScrollView::setFocus(0);
755
Q3ListBoxItem *item = listBox()->item(child -1);
758
listBox()->setCurrentItem(item);
763
Selects the item with index \a child if \a on is true; otherwise
764
unselects it. If \a extend is true and the selection mode is not
765
\c Single and there is an existing selection, the selection is
766
extended to include all the items from the existing selection up
767
to and including the item with index \a child. Returns true if a
768
selection was made or extended; otherwise returns false.
770
\sa selection() clearSelection()
772
bool QAccessibleListBox::setSelected(int child, bool on, bool extend)
774
if (!child || (extend &&
775
listBox()->selectionMode() != Q3ListBox::Extended &&
776
listBox()->selectionMode() != Q3ListBox::Multi))
779
Q3ListBoxItem *item = listBox()->item(child -1);
783
listBox()->setSelected(item, on);
785
int current = listBox()->currentItem();
786
bool down = child > current;
787
for (int i = current; i != child;) {
789
listBox()->setSelected(i, on);
797
Sets all the items in the list box to be unselected.
799
\sa setSelected() selection()
801
void QAccessibleListBox::clearSelection()
803
listBox()->clearSelection();
807
Returns a (possibly empty) list of indexes of the items selected
810
\sa setSelected() clearSelection()
812
QVector<int> QAccessibleListBox::selection() const
816
const uint c = listBox()->count();
818
for (uint i = 0; i < c; ++i) {
819
if (listBox()->isSelected(i)) {
821
array[(int)size-1] = i+1;