~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/plugins/accessible/compat/qaccessiblecompat.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the accessibility module of the Qt Toolkit.
 
6
**
 
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.
 
10
**
 
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.
 
15
**
 
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.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
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.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#include "qaccessiblecompat.h"
 
30
#include "q3widgetstack.h"
 
31
 
 
32
#include <q3listview.h>
 
33
#include <q3textedit.h>
 
34
#include <q3iconview.h>
 
35
#include <q3listbox.h>
 
36
 
 
37
/*!
 
38
\fn Q3AccessibleScrollView::Q3AccessibleScrollView(QWidget* widget, Role role)
 
39
 
 
40
Constructs a Q3AccessibleScrollView object for a \a widget.
 
41
The \a role is propagated to the QAccessibleWidget constructor.
 
42
*/
 
43
Q3AccessibleScrollView::Q3AccessibleScrollView(QWidget *w, Role role)
 
44
: QAccessibleWidget(w, role)
 
45
{
 
46
}
 
47
 
 
48
/*!
 
49
  Returns the ID of the item at viewport position \a x, \a y.
 
50
*/
 
51
int Q3AccessibleScrollView::itemAt(int /*x*/, int /*y*/) const
 
52
{
 
53
    return 0;
 
54
}
 
55
 
 
56
/*!
 
57
  Returns the location in viewport coordinates of the item with ID \a
 
58
  item.
 
59
*/
 
60
QRect Q3AccessibleScrollView::itemRect(int /*item*/) const
 
61
{
 
62
    return QRect();
 
63
}
 
64
 
 
65
/*!
 
66
  Returns the number of items in the scroll view.
 
67
*/
 
68
int Q3AccessibleScrollView::itemCount() const
 
69
{
 
70
    return 0;
 
71
}
 
72
 
 
73
/*!
 
74
  \class QAccessibleListView qaccessiblewidget.h
 
75
  \brief The QAccessibleListView class implements the QAccessibleInterface for list views.
 
76
  \internal
 
77
*/
 
78
 
 
79
static Q3ListViewItem *findLVItem(Q3ListView* listView, int child)
 
80
{
 
81
    int id = 1;
 
82
    Q3ListViewItemIterator it(listView);
 
83
    Q3ListViewItem *item = it.current();
 
84
    while (item && id < child) {
 
85
        ++it;
 
86
        ++id;
 
87
        item = it.current();
 
88
    }
 
89
    return item;
 
90
}
 
91
 
 
92
/*!
 
93
  \fn QAccessibleListView::QAccessibleListView(QWidget* widget)
 
94
 
 
95
  Constructs a QAccessibleListView object for a \a widget.
 
96
*/
 
97
QAccessibleListView::QAccessibleListView(QWidget *o)
 
98
    : Q3AccessibleScrollView(o, Tree)
 
99
{
 
100
}
 
101
 
 
102
/*! Returns the list view. */
 
103
Q3ListView *QAccessibleListView::listView() const
 
104
{
 
105
    Q_ASSERT(widget()->inherits("Q3ListView"));
 
106
    return (Q3ListView*)widget();
 
107
}
 
108
 
 
109
/*! \reimp */
 
110
int QAccessibleListView::itemAt(int x, int y) const
 
111
{
 
112
    Q3ListViewItem *item = listView()->itemAt(QPoint(x, y));
 
113
    if (!item)
 
114
        return 0;
 
115
 
 
116
    Q3ListViewItemIterator it(listView());
 
117
    int c = 1;
 
118
    while (it.current()) {
 
119
        if (it.current() == item)
 
120
            return c;
 
121
        ++c;
 
122
        ++it;
 
123
    }
 
124
    return 0;
 
125
}
 
126
 
 
127
/*! \reimp */
 
128
QRect QAccessibleListView::itemRect(int child) const
 
129
{
 
130
    Q3ListViewItem *item = findLVItem(listView(), child);
 
131
    if (!item)
 
132
        return QRect();
 
133
    return listView()->itemRect(item);
 
134
}
 
135
 
 
136
/*! \reimp */
 
137
int QAccessibleListView::itemCount() const
 
138
{
 
139
    Q3ListViewItemIterator it(listView());
 
140
    int c = 0;
 
141
    while (it.current()) {
 
142
        ++c;
 
143
        ++it;
 
144
    }
 
145
 
 
146
    return c;
 
147
}
 
148
 
 
149
/*! \reimp */
 
150
QString QAccessibleListView::text(Text t, int child) const
 
151
{
 
152
    if (!child || t != Name)
 
153
        return Q3AccessibleScrollView::text(t, child);
 
154
 
 
155
    Q3ListViewItem *item = findLVItem(listView(), child);
 
156
    if (!item)
 
157
        return QString();
 
158
    return item->text(0);
 
159
}
 
160
 
 
161
/*! \reimp */
 
162
QAccessible::Role QAccessibleListView::role(int child) const
 
163
{
 
164
    if (!child)
 
165
        return Q3AccessibleScrollView::role(child);
 
166
    return TreeItem;
 
167
}
 
168
 
 
169
/*! \reimp */
 
170
QAccessible::State QAccessibleListView::state(int child) const
 
171
{
 
172
    State state = Q3AccessibleScrollView::state(child);
 
173
    Q3ListViewItem *item;
 
174
    if (!child || !(item = findLVItem(listView(), child)))
 
175
        return state;
 
176
 
 
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)
 
183
            state |= Selectable;
 
184
        if (item->isSelected())
 
185
            state |= Selected;
 
186
    }
 
187
    if (listView()->focusPolicy() != Qt::NoFocus) {
 
188
        state |= Focusable;
 
189
        if (item == listView()->currentItem())
 
190
            state |= Focused;
 
191
    }
 
192
    if (item->childCount()) {
 
193
        if (item->isOpen())
 
194
            state |= Expanded;
 
195
        else
 
196
            state |= Collapsed;
 
197
    }
 
198
    if (!listView()->itemRect(item).isValid())
 
199
        state |= Invisible;
 
200
 
 
201
    if (item->rtti() == Q3CheckListItem::RTTI) {
 
202
        if (((Q3CheckListItem*)item)->isOn())
 
203
            state|=Checked;
 
204
    }
 
205
    return state;
 
206
}
 
207
 
 
208
/* \reimp
 
209
QAccessibleInterface *QAccessibleListView::focusChild(int *child) const
 
210
{
 
211
    Q3ListViewItem *item = listView()->currentItem();
 
212
    if (!item)
 
213
        return 0;
 
214
 
 
215
    Q3ListViewItemIterator it(listView());
 
216
    int c = 1;
 
217
    while (it.current()) {
 
218
        if (it.current() == item) {
 
219
            *child = c;
 
220
            return (QAccessibleInterface*)this;
 
221
        }
 
222
        ++c;
 
223
        ++it;
 
224
    }
 
225
    return 0;
 
226
}
 
227
*/
 
228
/* \reimp
 
229
bool QAccessibleListView::setFocus(int child)
 
230
{
 
231
    bool res = Q3AccessibleScrollView::setFocus(0);
 
232
    if (!child || !res)
 
233
        return res;
 
234
 
 
235
    Q3ListViewItem *item = findLVItem(listView(), child);
 
236
    if (!item)
 
237
        return false;
 
238
    listView()->setCurrentItem(item);
 
239
    return true;
 
240
}*/
 
241
 
 
242
/*! \internal */
 
243
bool QAccessibleListView::setSelected(int child, bool on, bool extend)
 
244
{
 
245
    if (!child || (extend &&
 
246
        listView()->selectionMode() != Q3ListView::Extended &&
 
247
        listView()->selectionMode() != Q3ListView::Multi))
 
248
        return false;
 
249
 
 
250
    Q3ListViewItem *item = findLVItem(listView(), child);
 
251
    if (!item)
 
252
        return false;
 
253
    if (!extend) {
 
254
        listView()->setSelected(item, on);
 
255
    } else {
 
256
        Q3ListViewItem *current = listView()->currentItem();
 
257
        if (!current)
 
258
            return false;
 
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)
 
264
                break;
 
265
            if (down)
 
266
                ++it;
 
267
            else
 
268
                --it;
 
269
        }
 
270
    }
 
271
    return true;
 
272
}
 
273
 
 
274
/*! \internal */
 
275
void QAccessibleListView::clearSelection()
 
276
{
 
277
    listView()->clearSelection();
 
278
}
 
279
 
 
280
/*! \internal */
 
281
QVector<int> QAccessibleListView::selection() const
 
282
{
 
283
    QVector<int> array;
 
284
    uint size = 0;
 
285
    int id = 1;
 
286
    array.resize(size);
 
287
    Q3ListViewItemIterator it(listView());
 
288
    while (it.current()) {
 
289
        if (it.current()->isSelected()) {
 
290
            ++size;
 
291
            array.resize(size);
 
292
            array[(int)size-1] = id;
 
293
        }
 
294
        ++it;
 
295
        ++id;
 
296
    }
 
297
    return array;
 
298
}
 
299
 
 
300
/*!
 
301
  \class QAccessibleIconView qaccessiblewidget.h
 
302
  \brief The QAccessibleIconView class implements the QAccessibleInterface for icon views.
 
303
  \internal
 
304
*/
 
305
 
 
306
static Q3IconViewItem *findIVItem(Q3IconView *iconView, int child)
 
307
{
 
308
    int id = 1;
 
309
    Q3IconViewItem *item = iconView->firstItem();
 
310
    while (item && id < child) {
 
311
        item = item->nextItem();
 
312
        ++id;
 
313
    }
 
314
 
 
315
    return item;
 
316
}
 
317
 
 
318
/*!
 
319
  \fn QAccessibleIconView::QAccessibleIconView(QWidget* widget)
 
320
 
 
321
  Constructs a QAccessibleIconView object for a \a widget.
 
322
*/
 
323
QAccessibleIconView::QAccessibleIconView(QWidget *o)
 
324
    : Q3AccessibleScrollView(o, List)
 
325
{
 
326
    Q_ASSERT(widget()->inherits("Q3IconView"));
 
327
}
 
328
 
 
329
/*! Returns the icon view. */
 
330
Q3IconView *QAccessibleIconView::iconView() const
 
331
{
 
332
    return (Q3IconView*)widget();
 
333
}
 
334
 
 
335
/*! \internal */
 
336
int QAccessibleIconView::itemAt(int x, int y) const
 
337
{
 
338
    Q3IconViewItem *item = iconView()->findItem(QPoint(x, y));
 
339
    return iconView()->index(item) + 1;
 
340
}
 
341
 
 
342
/*! \internal */
 
343
QRect QAccessibleIconView::itemRect(int child) const
 
344
{
 
345
    Q3IconViewItem *item = findIVItem(iconView(), child);
 
346
 
 
347
    if (!item)
 
348
        return QRect();
 
349
    return item->rect();
 
350
}
 
351
 
 
352
/*! \internal */
 
353
int QAccessibleIconView::itemCount() const
 
354
{
 
355
    return iconView()->count();
 
356
}
 
357
 
 
358
/*! \internal */
 
359
QString QAccessibleIconView::text(Text t, int child) const
 
360
{
 
361
    if (!child || t != Name)
 
362
        return Q3AccessibleScrollView::text(t, child);
 
363
 
 
364
    Q3IconViewItem *item = findIVItem(iconView(), child);
 
365
    if (!item)
 
366
        return QString();
 
367
    return item->text();
 
368
}
 
369
 
 
370
/*! \internal */
 
371
QAccessible::Role QAccessibleIconView::role(int child) const
 
372
{
 
373
    if (!child)
 
374
        return Q3AccessibleScrollView::role(child);
 
375
    return ListItem;
 
376
}
 
377
 
 
378
/*! \internal */
 
379
QAccessible::State QAccessibleIconView::state(int child) const
 
380
{
 
381
    State state = Q3AccessibleScrollView::state(child);
 
382
    Q3IconViewItem *item;
 
383
    if (!child || !(item = findIVItem(iconView(), child)))
 
384
        return state;
 
385
 
 
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)
 
392
            state |= Selectable;
 
393
        if (item->isSelected())
 
394
            state |= Selected;
 
395
    }
 
396
    if (iconView()->itemsMovable())
 
397
        state |= Movable;
 
398
    if (iconView()->focusPolicy() != Qt::NoFocus) {
 
399
        state |= Focusable;
 
400
        if (item == iconView()->currentItem())
 
401
            state |= Focused;
 
402
    }
 
403
 
 
404
    return state;
 
405
}
 
406
 
 
407
/* \reimp
 
408
QAccessibleInterface *QAccessibleIconView::focusChild(int *child) const
 
409
{
 
410
    Q3IconViewItem *item = iconView()->currentItem();
 
411
    if (!item)
 
412
        return 0;
 
413
 
 
414
    *child = iconView()->index(item);
 
415
    return (QAccessibleInterface*)this;
 
416
}
 
417
*/
 
418
/* \reimp
 
419
bool QAccessibleIconView::setFocus(int child)
 
420
{
 
421
    bool res = Q3AccessibleScrollView::setFocus(0);
 
422
    if (!child || !res)
 
423
        return res;
 
424
 
 
425
    Q3IconViewItem *item = findIVItem(iconView(), child);
 
426
    if (!item)
 
427
        return false;
 
428
    iconView()->setCurrentItem(item);
 
429
    return true;
 
430
}*/
 
431
 
 
432
/*! \internal */
 
433
bool QAccessibleIconView::setSelected(int child, bool on, bool extend)
 
434
{
 
435
    if (!child || (extend &&
 
436
        iconView()->selectionMode() != Q3IconView::Extended &&
 
437
        iconView()->selectionMode() != Q3IconView::Multi))
 
438
        return false;
 
439
 
 
440
    Q3IconViewItem *item = findIVItem(iconView(), child);
 
441
    if (!item)
 
442
        return false;
 
443
    if (!extend) {
 
444
        iconView()->setSelected(item, on, true);
 
445
    } else {
 
446
        Q3IconViewItem *current = iconView()->currentItem();
 
447
        if (!current)
 
448
            return false;
 
449
        bool down = false;
 
450
        Q3IconViewItem *temp = current;
 
451
        while ((temp = temp->nextItem())) {
 
452
            if (temp == item) {
 
453
                down = true;
 
454
                break;
 
455
            }
 
456
        }
 
457
        temp = current;
 
458
        if (down) {
 
459
            while ((temp = temp->nextItem())) {
 
460
                iconView()->setSelected(temp, on, true);
 
461
                if (temp == item)
 
462
                    break;
 
463
            }
 
464
        } else {
 
465
            while ((temp = temp->prevItem())) {
 
466
                iconView()->setSelected(temp, on, true);
 
467
                if (temp == item)
 
468
                    break;
 
469
            }
 
470
        }
 
471
    }
 
472
    return true;
 
473
}
 
474
 
 
475
/*! \internal */
 
476
void QAccessibleIconView::clearSelection()
 
477
{
 
478
    iconView()->clearSelection();
 
479
}
 
480
 
 
481
/*! \internal */
 
482
QVector<int> QAccessibleIconView::selection() const
 
483
{
 
484
    QVector<int> array;
 
485
    uint size = 0;
 
486
    int id = 1;
 
487
    array.resize(iconView()->count());
 
488
    Q3IconViewItem *item = iconView()->firstItem();
 
489
    while (item) {
 
490
        if (item->isSelected()) {
 
491
            ++size;
 
492
            array[(int)size-1] = id;
 
493
        }
 
494
        item = item->nextItem();
 
495
        ++id;
 
496
    }
 
497
    array.resize(size);
 
498
    return array;
 
499
}
 
500
 
 
501
 
 
502
/*!
 
503
  \class QAccessibleTextEdit qaccessiblewidget.h
 
504
  \brief The QAccessibleTextEdit class implements the QAccessibleInterface for richtext editors.
 
505
  \internal
 
506
*/
 
507
 
 
508
/*!
 
509
  \fn QAccessibleTextEdit::QAccessibleTextEdit(QWidget* widget)
 
510
 
 
511
  Constructs a QAccessibleTextEdit object for a \a widget.
 
512
*/
 
513
QAccessibleTextEdit::QAccessibleTextEdit(QWidget *o)
 
514
: Q3AccessibleScrollView(o, Pane)
 
515
{
 
516
    Q_ASSERT(widget()->inherits("Q3TextEdit"));
 
517
}
 
518
 
 
519
/*! Returns the text edit. */
 
520
Q3TextEdit *QAccessibleTextEdit::textEdit() const
 
521
{
 
522
 
 
523
    return (Q3TextEdit*)widget();
 
524
}
 
525
 
 
526
/*! \reimp */
 
527
int QAccessibleTextEdit::itemAt(int x, int y) const
 
528
{
 
529
    int p;
 
530
    QPoint cp = textEdit()->viewportToContents(QPoint(x,y));
 
531
    textEdit()->charAt(cp , &p);
 
532
    return p + 1;
 
533
}
 
534
 
 
535
/*! \reimp */
 
536
QRect QAccessibleTextEdit::itemRect(int item) const
 
537
{
 
538
    QRect rect = textEdit()->paragraphRect(item - 1);
 
539
    if (!rect.isValid())
 
540
        return QRect();
 
541
    QPoint ntl = textEdit()->contentsToViewport(QPoint(rect.x(), rect.y()));
 
542
    return QRect(ntl.x(), ntl.y(), rect.width(), rect.height());
 
543
}
 
544
 
 
545
/*! \reimp */
 
546
int QAccessibleTextEdit::itemCount() const
 
547
{
 
548
    return textEdit()->paragraphs();
 
549
}
 
550
 
 
551
/*! \reimp */
 
552
QString QAccessibleTextEdit::text(Text t, int child) const
 
553
{
 
554
    if (t == Name && child > 0)
 
555
        return textEdit()->text(child - 1);
 
556
    if (t == Value) {
 
557
        if (child > 0)
 
558
            return textEdit()->text(child - 1);
 
559
        else
 
560
            return textEdit()->text();
 
561
    }
 
562
 
 
563
    return Q3AccessibleScrollView::text(t, child);
 
564
}
 
565
 
 
566
/*! \reimp */
 
567
void QAccessibleTextEdit::setText(Text t, int control, const QString &text)
 
568
{
 
569
    if (t != Value || control) {
 
570
        Q3AccessibleScrollView::setText(t, control, text);
 
571
        return;
 
572
    }
 
573
    textEdit()->setText(text);
 
574
}
 
575
 
 
576
/*! \reimp */
 
577
QAccessible::Role QAccessibleTextEdit::role(int child) const
 
578
{
 
579
    if (child)
 
580
        return EditableText;
 
581
    return Q3AccessibleScrollView::role(child);
 
582
}
 
583
 
 
584
/*!
 
585
  \class QAccessibleWidgetStack qaccessible.h
 
586
  \brief The QAccessibleWidgetStack class implements the QAccessibleInterface for widget stacks.
 
587
 
 
588
  \ingroup accessibility
 
589
  \internal
 
590
*/
 
591
 
 
592
/*!
 
593
  \fn QAccessibleWidgetStack::QAccessibleWidgetStack(QWidget* widget)
 
594
 
 
595
  Creates a QAccessibleWidgetStack object for a \a widget.
 
596
*/
 
597
QAccessibleWidgetStack::QAccessibleWidgetStack(QWidget *w)
 
598
: QAccessibleWidget(w, LayeredPane)
 
599
{
 
600
    Q_ASSERT(widgetStack());
 
601
    setDescription("This is a widgetstack");
 
602
}
 
603
 
 
604
/*! Returns the widget stack. */
 
605
Q3WidgetStack *QAccessibleWidgetStack::widgetStack() const
 
606
{
 
607
    return qobject_cast<Q3WidgetStack*>(object());
 
608
}
 
609
 
 
610
/*! \reimp */
 
611
int QAccessibleWidgetStack::childCount() const
 
612
{
 
613
    // a widget stack has always only one accessible widget
 
614
    return 1;
 
615
}
 
616
 
 
617
/*! \reimp */
 
618
int QAccessibleWidgetStack::indexOfChild(const QAccessibleInterface *child) const
 
619
{
 
620
    QObject *childObject = child ? child->object() : 0;
 
621
    if (childObject != widgetStack()->visibleWidget())
 
622
        return -1;
 
623
    return 1;
 
624
}
 
625
 
 
626
/*! \reimp */
 
627
int QAccessibleWidgetStack::childAt(int, int) const
 
628
{
 
629
    QWidget *curPage = widgetStack()->visibleWidget();
 
630
    if (!curPage)
 
631
        return 0;
 
632
    return 1;
 
633
}
 
634
 
 
635
/*! \reimp */
 
636
int QAccessibleWidgetStack::navigate(RelationFlag rel, int entry,
 
637
                                     QAccessibleInterface **target) const
 
638
{
 
639
    *target = 0;
 
640
    QObject *targetObject = 0;
 
641
    switch (rel) {
 
642
    // Hierarchical
 
643
    case Child:
 
644
        if (entry != 1)
 
645
            return -1;
 
646
        targetObject = widgetStack()->visibleWidget();
 
647
        break;
 
648
    default:
 
649
        return QAccessibleWidget::navigate(rel, entry, target);
 
650
    }
 
651
    *target = QAccessible::queryAccessibleInterface(targetObject);
 
652
    return *target ? 0 : -1;
 
653
}
 
654
 
 
655
/*!
 
656
  \class QAccessibleListBox qaccessiblewidget.h
 
657
  \brief The QAccessibleListBox class implements the QAccessibleInterface for list boxes.
 
658
 
 
659
  \ingroup accessibility
 
660
  \internal
 
661
*/
 
662
 
 
663
/*!
 
664
  \fn QAccessibleListBox::QAccessibleListBox(QWidget* widget)
 
665
 
 
666
  Constructs a QAccessibleListBox object for a \a widget.
 
667
*/
 
668
QAccessibleListBox::QAccessibleListBox(QWidget *o)
 
669
    : Q3AccessibleScrollView(o, List)
 
670
{
 
671
    Q_ASSERT(widget()->inherits("Q3ListBox"));
 
672
}
 
673
 
 
674
/*! Returns the list box. */
 
675
Q3ListBox *QAccessibleListBox::listBox() const
 
676
{
 
677
    return (Q3ListBox*)widget();
 
678
}
 
679
 
 
680
/*! \reimp */
 
681
int QAccessibleListBox::itemAt(int x, int y) const
 
682
{
 
683
    Q3ListBoxItem *item = listBox()->itemAt(QPoint(x, y));
 
684
    return listBox()->index(item) + 1;
 
685
}
 
686
 
 
687
/*! \reimp */
 
688
QRect QAccessibleListBox::itemRect(int item) const
 
689
{
 
690
    return listBox()->itemRect(listBox()->item(item-1));
 
691
}
 
692
 
 
693
/*! \reimp */
 
694
int QAccessibleListBox::itemCount() const
 
695
{
 
696
    return listBox()->count();
 
697
}
 
698
 
 
699
/*! \reimp */
 
700
QString QAccessibleListBox::text(Text t, int child) const
 
701
{
 
702
    if (!child || t != Name)
 
703
        return Q3AccessibleScrollView::text(t, child);
 
704
 
 
705
    Q3ListBoxItem *item = listBox()->item(child - 1);
 
706
    if (item)
 
707
        return item->text();
 
708
    return QString();
 
709
}
 
710
 
 
711
/*! \reimp */
 
712
QAccessible::Role QAccessibleListBox::role(int child) const
 
713
{
 
714
    if (!child)
 
715
        return Q3AccessibleScrollView::role(child);
 
716
    return ListItem;
 
717
}
 
718
 
 
719
/*! \reimp */
 
720
QAccessible::State QAccessibleListBox::state(int child) const
 
721
{
 
722
    State state = Q3AccessibleScrollView::state(child);
 
723
    Q3ListBoxItem *item;
 
724
    if (!child || !(item = listBox()->item(child - 1)))
 
725
        return state;
 
726
 
 
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)
 
733
            state |= Selectable;
 
734
        if (item->isSelected())
 
735
            state |= Selected;
 
736
    }
 
737
    if (listBox()->focusPolicy() != Qt::NoFocus) {
 
738
        state |= Focusable;
 
739
        if (item->isCurrent())
 
740
            state |= Focused;
 
741
    }
 
742
    if (!listBox()->itemVisible(item))
 
743
        state |= Invisible;
 
744
 
 
745
    return state;
 
746
}
 
747
 
 
748
/* \reimp
 
749
bool QAccessibleListBox::setFocus(int child)
 
750
{
 
751
    bool res = Q3AccessibleScrollView::setFocus(0);
 
752
    if (!child || !res)
 
753
        return res;
 
754
 
 
755
    Q3ListBoxItem *item = listBox()->item(child -1);
 
756
    if (!item)
 
757
        return false;
 
758
    listBox()->setCurrentItem(item);
 
759
    return true;
 
760
}*/
 
761
 
 
762
/*!
 
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.
 
769
 
 
770
    \sa selection() clearSelection()
 
771
*/
 
772
bool QAccessibleListBox::setSelected(int child, bool on, bool extend)
 
773
{
 
774
    if (!child || (extend &&
 
775
        listBox()->selectionMode() != Q3ListBox::Extended &&
 
776
        listBox()->selectionMode() != Q3ListBox::Multi))
 
777
        return false;
 
778
 
 
779
    Q3ListBoxItem *item = listBox()->item(child -1);
 
780
    if (!item)
 
781
        return false;
 
782
    if (!extend) {
 
783
        listBox()->setSelected(item, on);
 
784
    } else {
 
785
        int current = listBox()->currentItem();
 
786
        bool down = child > current;
 
787
        for (int i = current; i != child;) {
 
788
            down ? i++ : i--;
 
789
            listBox()->setSelected(i, on);
 
790
        }
 
791
 
 
792
    }
 
793
    return true;
 
794
}
 
795
 
 
796
/*!
 
797
    Sets all the items in the list box to be unselected.
 
798
 
 
799
    \sa setSelected() selection()
 
800
*/
 
801
void QAccessibleListBox::clearSelection()
 
802
{
 
803
    listBox()->clearSelection();
 
804
}
 
805
 
 
806
/*!
 
807
    Returns a (possibly empty) list of indexes of the items selected
 
808
    in the list box.
 
809
 
 
810
    \sa setSelected() clearSelection()
 
811
*/
 
812
QVector<int> QAccessibleListBox::selection() const
 
813
{
 
814
    QVector<int> array;
 
815
    uint size = 0;
 
816
    const uint c = listBox()->count();
 
817
    array.resize(c);
 
818
    for (uint i = 0; i < c; ++i) {
 
819
        if (listBox()->isSelected(i)) {
 
820
            ++size;
 
821
            array[(int)size-1] = i+1;
 
822
        }
 
823
    }
 
824
    array.resize(size);
 
825
    return array;
 
826
}