source: trunk/plugins/src/accessible/widgets/qaccessiblewidget.cpp

Last change on this file was 204, checked in by rudi, 14 years ago

Added plugin source code

File size: 69.2 KB
Line 
1#include "qaccessiblewidget.h"
2
3#include <qapplication.h>
4#include <qstyle.h>
5#include <qobjectlist.h>
6#include <qpushbutton.h>
7#include <qslider.h>
8#include <qdial.h>
9#include <qspinbox.h>
10#include <qscrollbar.h>
11#include <qslider.h>
12#include <qlineedit.h>
13#include <qlabel.h>
14#include <qlcdnumber.h>
15#include <qprogressbar.h>
16#include <qgroupbox.h>
17#include <qtoolbutton.h>
18#include <qwhatsthis.h>
19#include <qtooltip.h>
20#include <qscrollview.h>
21#include <qheader.h>
22#include <qtabbar.h>
23#include <qcombobox.h>
24#include <qrangecontrol.h>
25#include <qlistbox.h>
26#include <qlistview.h>
27#include <qiconview.h>
28#include <qtextedit.h>
29#include <qwidgetstack.h>
30#include <private/qtitlebar_p.h>
31
32
33QString buddyString( QWidget *widget )
34{
35 QWidget *parent = widget->parentWidget();
36 QObjectList *ol = parent->queryList( "QLabel", 0, FALSE, FALSE );
37 if ( !ol || !ol->count() ) {
38 delete ol;
39 return QString::null;
40 }
41
42 QString str;
43
44 QObjectListIt it(*ol);
45 while ( it.current() ) {
46 QLabel *label = (QLabel*)it.current();
47 ++it;
48 if ( label->buddy() == widget ) {
49 str = label->text();
50 break;
51 }
52 }
53 delete ol;
54 if ( !!str )
55 return str;
56
57 if ( parent->inherits( "QGroupBox" ) )
58 return ((QGroupBox*)parent)->title();
59
60 return QString::null;
61}
62
63QString stripAmp( const QString &text )
64{
65 if ( text.isEmpty() )
66 return text;
67
68 QString n = text;
69 for ( uint i = 0; i < n.length(); i++ ) {
70 if ( n[(int)i] == '&' )
71 n.remove( i, 1 );
72 }
73 return n;
74}
75
76QString hotKey( const QString &text )
77{
78 if ( text.isEmpty() )
79 return text;
80
81 QString n = text;
82 int fa = 0;
83 bool ac = FALSE;
84 while ( ( fa = n.find( "&", fa ) ) != -1 ) {
85 if ( n.at(fa+1) != '&' ) {
86 ac = TRUE;
87 break;
88 }
89 }
90 if ( fa != -1 && ac )
91 return QString( n.at(fa + 1) );
92
93 return QString::null;
94}
95
96/*!
97 \class QAccessibleWidget qaccessiblewidget.h
98 \brief The QAccessibleWidget class implements the QAccessibleInterface for QWidgets.
99*/
100
101ulong QAccessibleWidget::objects = 0;
102
103/*!
104 Creates a QAccessibleWidget object for \a o.
105 \a role, \a name, \a description, \a value, \a help, \a defAction,
106 \a accelerator and \a state are optional parameters for static values
107 of the object's property.
108*/
109QAccessibleWidget::QAccessibleWidget( QObject *o, Role role, QString name,
110 QString description, QString value, QString help, QString defAction, QString accelerator, State state )
111 : QAccessibleObject( o ), role_(role), state_(state), name_(name),
112 description_(description),value_(value),help_(help),
113 defAction_(defAction), accelerator_(accelerator)
114{
115 objects++;
116}
117
118QAccessibleWidget::~QAccessibleWidget()
119{
120 objects--;
121}
122
123/*! Returns the widget. */
124QWidget *QAccessibleWidget::widget() const
125{
126 Q_ASSERT(object()->isWidgetType());
127 if ( !object()->isWidgetType() )
128 return 0;
129 return (QWidget*)object();
130}
131
132/*! \reimp */
133int QAccessibleWidget::controlAt( int x, int y ) const
134{
135 QWidget *w = widget();
136 QPoint gp = w->mapToGlobal( QPoint( 0, 0 ) );
137 if ( !QRect( gp.x(), gp.y(), w->width(), w->height() ).contains( x, y ) )
138 return -1;
139
140 QPoint rp = w->mapFromGlobal( QPoint( x, y ) );
141
142 QObjectList *list = w->queryList( "QWidget", 0, FALSE, FALSE );
143
144 if ( !list || list->isEmpty() )
145 return 0;
146
147 QObjectListIt it( *list );
148 QWidget *child = 0;
149 int index = 1;
150 while ( ( child = (QWidget*)it.current() ) ) {
151 if ( !child->isTopLevel() && !child->isHidden() && child->geometry().contains( rp ) ) {
152 delete list;
153 return index;
154 }
155 ++it;
156 ++index;
157 }
158 delete list;
159 return 0;
160}
161
162/*! \reimp */
163QRect QAccessibleWidget::rect( int control ) const
164{
165#if defined(QT_DEBUG)
166 if ( control )
167 qWarning( "QAccessibleWidget::rect: This implementation does not support subelements! (ID %d unknown for %s)", control, widget()->className() );
168#else
169 Q_UNUSED(control)
170#endif
171 QWidget *w = widget();
172 QPoint wpos = w->mapToGlobal( QPoint( 0, 0 ) );
173
174 return QRect( wpos.x(), wpos.y(), w->width(), w->height() );
175}
176
177/*! \reimp */
178int QAccessibleWidget::navigate( NavDirection dir, int startControl ) const
179{
180#if defined(QT_DEBUG)
181 if ( startControl )
182 qWarning( "QAccessibleWidget::navigate: This implementation does not support subelements! (ID %d unknown for %s)", startControl, widget()->className() );
183#else
184 Q_UNUSED(startControl);
185#endif
186 QWidget *w = widget();
187 switch ( dir ) {
188 case NavFirstChild:
189 {
190 QObjectList *list = w->queryList( "QWidget", 0, FALSE, FALSE );
191 bool has = !list->isEmpty();
192 delete list;
193 return has ? 1 : -1;
194 }
195 case NavLastChild:
196 {
197 QObjectList *list = w->queryList( "QWidget", 0, FALSE, FALSE );
198 bool has = !list->isEmpty();
199 delete list;
200 return has ? childCount() : -1;
201 }
202 case NavNext:
203 case NavPrevious:
204 {
205 QWidget *parent = w->parentWidget();
206 QObjectList *sl = parent ? parent->queryList( "QWidget", 0, FALSE, FALSE ) : 0;
207 if ( !sl )
208 return -1;
209 QObject *sib;
210 QObjectListIt it( *sl );
211 int index;
212 if ( dir == NavNext ) {
213 index = 1;
214 while ( ( sib = it.current() ) ) {
215 ++it;
216 ++index;
217 if ( sib == w )
218 break;
219 }
220 } else {
221 it.toLast();
222 index = sl->count();
223 while ( ( sib = it.current() ) ) {
224 --it;
225 --index;
226 if ( sib == w )
227 break;
228 }
229 }
230 sib = it.current();
231 delete sl;
232 if ( sib )
233 return index;
234 return -1;
235 }
236 break;
237 case NavFocusChild:
238 {
239 if ( w->hasFocus() )
240 return 0;
241
242 QWidget *w2 = w->focusWidget();
243 if ( !w2 )
244 return -1;
245
246 QObjectList *list = w->queryList( "QWidget", 0, FALSE, FALSE );
247 int index = list->findRef( w2 );
248 delete list;
249 return ( index != -1 ) ? index+1 : -1;
250 }
251 default:
252 qWarning( "QAccessibleWidget::navigate: unhandled request" );
253 break;
254 };
255 return -1;
256}
257
258/*! \reimp */
259int QAccessibleWidget::childCount() const
260{
261 QObjectList *cl = widget()->queryList( "QWidget", 0, FALSE, FALSE );
262 if ( !cl )
263 return 0;
264
265 int count = cl->count();
266 delete cl;
267 return count;
268}
269
270/*! \reimp */
271QRESULT QAccessibleWidget::queryChild( int control, QAccessibleInterface **iface ) const
272{
273 *iface = 0;
274 QObjectList *cl = widget()->queryList( "QWidget", 0, FALSE, FALSE );
275 if ( !cl )
276 return QS_FALSE;
277
278 QObject *o = 0;
279 if ( cl->count() >= (uint)control )
280 o = cl->at( control-1 );
281 delete cl;
282
283 if ( !o )
284 return QS_FALSE;
285
286 return QAccessible::queryAccessibleInterface( o, iface );
287}
288
289/*! \reimp */
290QRESULT QAccessibleWidget::queryParent( QAccessibleInterface **iface ) const
291{
292 return QAccessible::queryAccessibleInterface( widget()->parentWidget(), iface );
293}
294
295/*! \reimp */
296bool QAccessibleWidget::doDefaultAction( int control )
297{
298#if defined(QT_DEBUG)
299 if ( control )
300 qWarning( "QAccessibleWidget::doDefaultAction: This implementation does not support subelements! (ID %d unknown for %s)", control, widget()->className() );
301#else
302 Q_UNUSED(control)
303#endif
304 return FALSE;
305}
306
307/*! \reimp */
308QString QAccessibleWidget::text( Text t, int control ) const
309{
310 switch ( t ) {
311 case DefaultAction:
312 return defAction_;
313 case Description:
314 if ( !control && description_.isNull() ) {
315 QString desc = QToolTip::textFor( widget() );
316 return desc;
317 }
318 return description_;
319 case Help:
320 if ( !control && help_.isNull() ) {
321 QString help = QWhatsThis::textFor( widget() );
322 return help;
323 }
324 return help_;
325 case Accelerator:
326 return accelerator_;
327 case Name:
328 {
329 if ( !control && name_.isNull() && widget()->isTopLevel() )
330 return widget()->caption();
331 return name_;
332 }
333 case Value:
334 return value_;
335 default:
336 break;
337 }
338 return QString::null;
339}
340
341/*! \reimp */
342void QAccessibleWidget::setText( Text t, int /*control*/, const QString &text )
343{
344 switch ( t ) {
345 case DefaultAction:
346 defAction_ = text;
347 break;
348 case Description:
349 description_ = text;
350 break;
351 case Help:
352 help_ = text;
353 break;
354 case Accelerator:
355 accelerator_ = text;
356 break;
357 case Name:
358 name_ = text;
359 break;
360 case Value:
361 value_ = text;
362 break;
363 default:
364 break;
365 }
366}
367
368/*! \reimp */
369QAccessible::Role QAccessibleWidget::role( int control ) const
370{
371 if ( !control )
372 return role_;
373 return NoRole;
374}
375
376/*! \reimp */
377QAccessible::State QAccessibleWidget::state( int control ) const
378{
379 if ( control )
380 return Normal;
381
382 if ( state_ != Normal )
383 return state_;
384
385 int state = Normal;
386
387 QWidget *w = widget();
388 if ( w->isHidden() )
389 state |= Invisible;
390 if ( w->focusPolicy() != QWidget::NoFocus && w->isActiveWindow() )
391 state |= Focusable;
392 if ( w->hasFocus() )
393 state |= Focused;
394 if ( !w->isEnabled() )
395 state |= Unavailable;
396 if ( w->isTopLevel() ) {
397 state |= Moveable;
398 if ( w->minimumSize() != w->maximumSize() )
399 state |= Sizeable;
400 }
401
402 return (State)state;
403}
404
405/*! \reimp */
406bool QAccessibleWidget::setFocus( int control )
407{
408#if defined(QT_DEBUG)
409 if ( control )
410 qWarning( "QAccessibleWidget::setFocus: This implementation does not support subelements! (ID %d unknown for %s)", control, widget()->className() );
411#else
412 Q_UNUSED(control)
413#endif
414 if ( widget()->focusPolicy() != QWidget::NoFocus ) {
415 widget()->setFocus();
416 return TRUE;
417 }
418 return FALSE;
419}
420
421/*! \reimp */
422bool QAccessibleWidget::setSelected( int, bool, bool )
423{
424#if defined(QT_DEBUG)
425 qWarning( "QAccessibleWidget::setSelected: This function not supported for simple widgets." );
426#endif
427 return FALSE;
428}
429
430/*! \reimp */
431void QAccessibleWidget::clearSelection()
432{
433#if defined(QT_DEBUG)
434 qWarning( "QAccessibleWidget::clearSelection: This function not supported for simple widgets." );
435#endif
436}
437
438/*! \reimp */
439QMemArray<int> QAccessibleWidget::selection() const
440{
441 return QMemArray<int>();
442}
443
444/*!
445 \class QAccessibleWidgetStack qaccessible.h
446 \brief The QAccessibleWidgetStack class implements the QAccessibleInterface for widget stacks.
447*/
448
449/*!
450 Creates a QAccessibleWidgetStack object for \a o.
451*/
452QAccessibleWidgetStack::QAccessibleWidgetStack( QObject *o )
453: QAccessibleWidget( o )
454{
455 Q_ASSERT( o->inherits("QWidgetStack") );
456}
457
458/*! Returns the widget stack. */
459QWidgetStack *QAccessibleWidgetStack::widgetStack() const
460{
461 return (QWidgetStack*)object();
462}
463
464/*! \reimp */
465int QAccessibleWidgetStack::controlAt( int, int ) const
466{
467 return widgetStack()->id( widgetStack()->visibleWidget() ) + 1;
468}
469
470/*! \reimp */
471QRESULT QAccessibleWidgetStack::queryChild( int control, QAccessibleInterface **iface ) const
472{
473 if ( !control ) {
474 *iface = (QAccessibleInterface*)this;
475 return QS_OK;
476 }
477
478 QWidget *widget = widgetStack()->widget( control - 1 );
479 if ( !widget )
480 return QAccessibleWidget::queryChild( control, iface );
481 return QAccessible::queryAccessibleInterface( widgetStack()->widget( control - 1 ), iface );
482}
483
484
485/*!
486 \class QAccessibleButton qaccessible.h
487 \brief The QAccessibleButton class implements the QAccessibleInterface for button type widgets.
488*/
489
490/*!
491 Creates a QAccessibleButton object for \a o.
492 \a role, \a description and \a help are propagated to the QAccessibleWidget constructor.
493*/
494QAccessibleButton::QAccessibleButton( QObject *o, Role role, QString description,
495 QString /* help */ )
496: QAccessibleWidget( o, role, QString::null, description, QString::null,
497 QString::null, QString::null, QString::null )
498{
499 Q_ASSERT(o->inherits("QButton"));
500}
501
502/*! \reimp */
503bool QAccessibleButton::doDefaultAction( int control )
504{
505 if ( !widget()->isEnabled() )
506 return FALSE;
507
508 Role r = role(control);
509 if ( r == PushButton || r == CheckBox || r == RadioButton ) {
510 ((QButton*)object())->animateClick();
511 } else if ( object()->inherits("QToolButton") ) {
512 QToolButton *tb = (QToolButton*)object();
513 tb->openPopup();
514 }
515
516 return TRUE;
517}
518
519/*! \reimp */
520QString QAccessibleButton::text( Text t, int control ) const
521{
522 QString tx = QAccessibleWidget::text( t, control );
523 if ( !!tx )
524 return tx;
525
526 switch ( t ) {
527 case DefaultAction:
528 switch( role(control) ) {
529 case PushButton:
530 return QButton::tr("Press");
531 case CheckBox:
532 if ( state(control) & Checked )
533 return QButton::tr("UnCheck");
534 return QButton::tr("Check");
535 case RadioButton:
536 return QButton::tr("Check");
537 default:
538 return QButton::tr("Press");
539 }
540 case Accelerator:
541 tx = hotKey( ((QButton*)widget())->text() );
542 if ( !!tx ) {
543 tx = "Alt + "+tx;
544 } else {
545 tx = hotKey( buddyString( widget() ) );
546 if ( !!tx )
547 tx = "Alt + "+tx;
548 }
549 return tx;
550 case Name:
551 tx = ((QButton*)widget())->text();
552 if ( tx.isEmpty() && widget()->inherits("QToolButton") )
553 tx = ((QToolButton*)widget())->textLabel();
554 if ( tx.isEmpty() )
555 tx = buddyString( widget() );
556
557 return stripAmp( tx );
558 default:
559 break;
560 }
561 return tx;
562}
563
564/*! \reimp */
565QAccessible::State QAccessibleButton::state( int control ) const
566{
567 int state = QAccessibleWidget::state( control );
568
569 QButton *b = (QButton*)widget();
570 if ( b->state() == QButton::On )
571 state |= Checked;
572 else if ( b->state() == QButton::NoChange )
573 state |= Mixed;
574 if ( b->isDown() )
575 state |= Pressed;
576 if ( b->inherits( "QPushButton" ) ) {
577 QPushButton *pb = (QPushButton*)b;
578 if ( pb->isDefault() )
579 state |= Default;
580 }
581
582 return (State)state;
583}
584
585/*!
586 \class QAccessibleRangeControl qaccessiblewidget.h
587 \brief The QAccessibleRangeControl class implements the QAccessibleInterface for range controls.
588*/
589
590/*!
591 Constructs a QAccessibleRangeControl object for \a o.
592 \a role, \a name, \a description, \a help, \a defAction and \a accelerator
593 are propagated to the QAccessibleWidget constructor.
594*/
595QAccessibleRangeControl::QAccessibleRangeControl( QObject *o, Role role, QString name,
596 QString description, QString help, QString defAction, QString accelerator )
597: QAccessibleWidget( o, role, name, description, QString::null, help, defAction, accelerator )
598{
599}
600
601/*! \reimp */
602QString QAccessibleRangeControl::text( Text t, int control ) const
603{
604 QString tx = QAccessibleWidget::text( t, control );
605 if ( !!tx )
606 return stripAmp(tx);
607
608 switch ( t ) {
609 case Name:
610 return stripAmp( buddyString( widget() ) );
611 case Accelerator:
612 tx = hotKey( buddyString( widget() ) );
613 if ( !!tx )
614 return "Alt + "+tx;
615 break;
616 case Value:
617 if ( widget()->inherits( "QSlider" ) ) {
618 QSlider *s = (QSlider*)widget();
619 return QString::number( s->value() );
620 } else if ( widget()->inherits( "QDial" ) ) {
621 QDial *d = (QDial*)widget();
622 return QString::number( d->value() );
623 } else if ( widget()->inherits( "QSpinBox" ) ) {
624 QSpinBox *s = (QSpinBox*)widget();
625 return s->text();
626 } else if ( widget()->inherits( "QScrollBar" ) ) {
627 QScrollBar *s = (QScrollBar*)widget();
628 return QString::number( s->value() );
629 } else if ( widget()->inherits( "QProgressBar" ) ) {
630 QProgressBar *p = (QProgressBar*)widget();
631 return QString::number( p->progress() );
632 }
633 default:
634 break;
635 }
636 return tx;
637}
638
639
640/*!
641 \class QAccessibleSpinWidget qaccessiblewidget.h
642 \brief The QAccessibleSpinWidget class implements the QAccessibleInterface for up/down widgets.
643*/
644
645/*!
646 Constructs a QAccessibleSpinWidget object for \a o.
647*/
648QAccessibleSpinWidget::QAccessibleSpinWidget( QObject *o )
649: QAccessibleRangeControl( o, SpinBox )
650{
651}
652
653/*! \reimp */
654int QAccessibleSpinWidget::controlAt( int x, int y ) const
655{
656 QPoint tl = widget()->mapFromGlobal( QPoint( x, y ) );
657 if ( ((QSpinWidget*)widget())->upRect().contains( tl ) )
658 return 1;
659 else if ( ((QSpinWidget*)widget())->downRect().contains( tl ) )
660 return 2;
661
662 return -1;
663}
664
665/*! \reimp */
666QRect QAccessibleSpinWidget::rect( int control ) const
667{
668 QRect rect;
669 switch( control ) {
670 case 1:
671 rect = ((QSpinWidget*)widget())->upRect();
672 break;
673 case 2:
674 rect = ((QSpinWidget*)widget())->downRect();
675 break;
676 default:
677 rect = widget()->rect();
678 }
679 QPoint tl = widget()->mapToGlobal( QPoint( 0, 0 ) );
680 return QRect( tl.x() + rect.x(), tl.y() + rect.y(), rect.width(), rect.height() );
681}
682
683/*! \reimp */
684int QAccessibleSpinWidget::navigate( NavDirection direction, int startControl ) const
685{
686 if ( direction != NavFirstChild && direction != NavLastChild && direction != NavFocusChild && !startControl )
687 return QAccessibleWidget::navigate( direction, startControl );
688
689 switch ( direction ) {
690 case NavFirstChild:
691 return 1;
692 case NavLastChild:
693 return 2;
694 case NavNext:
695 case NavDown:
696 startControl += 1;
697 if ( startControl > 2 )
698 return -1;
699 return startControl;
700 case NavPrevious:
701 case NavUp:
702 startControl -= 1;
703 if ( startControl < 1 )
704 return -1;
705 return startControl;
706 default:
707 break;
708 }
709
710 return -1;
711}
712
713/*! \reimp */
714int QAccessibleSpinWidget::childCount() const
715{
716 return 2;
717}
718
719/*! \reimp */
720QRESULT QAccessibleSpinWidget::queryChild( int /*control*/, QAccessibleInterface **iface ) const
721{
722 *iface = 0;
723 return QS_FALSE;
724}
725
726/*! \reimp */
727QString QAccessibleSpinWidget::text( Text t, int control ) const
728{
729 switch ( t ) {
730 case Name:
731 switch ( control ) {
732 case 1:
733 return QSpinWidget::tr("More");
734 case 2:
735 return QSpinWidget::tr("Less");
736 default:
737 break;
738 }
739 break;
740 case DefaultAction:
741 switch( control ) {
742 case 1:
743 case 2:
744 return QSpinWidget::tr("Press");
745 default:
746 break;
747 }
748 break;
749 default:
750 break;
751 }
752 return QAccessibleRangeControl::text( t, control );
753}
754
755/*! \reimp */
756QAccessible::Role QAccessibleSpinWidget::role( int control ) const
757{
758 switch( control ) {
759 case 1:
760 return PushButton;
761 case 2:
762 return PushButton;
763 default:
764 break;
765 }
766 return QAccessibleRangeControl::role( control );
767}
768
769/*! \reimp */
770QAccessible::State QAccessibleSpinWidget::state( int control ) const
771{
772 int state = QAccessibleRangeControl::state( control );
773 switch( control ) {
774 case 1:
775 if ( !((QSpinWidget*)widget())->isUpEnabled() )
776 state |= Unavailable;
777 return (State)state;
778 case 2:
779 if ( !((QSpinWidget*)widget())->isDownEnabled() )
780 state |= Unavailable;
781 return (State)state;
782 default:
783 break;
784 }
785 return QAccessibleRangeControl::state( control );
786}
787
788/*! \reimp */
789bool QAccessibleSpinWidget::doDefaultAction( int control )
790{
791 switch( control ) {
792 case 1:
793 if ( !((QSpinWidget*)widget())->isUpEnabled() )
794 return FALSE;
795 ((QSpinWidget*)widget())->stepUp();
796 return TRUE;
797 case 2:
798 if ( !((QSpinWidget*)widget())->isDownEnabled() )
799 return FALSE;
800 ((QSpinWidget*)widget())->stepDown();
801 return TRUE;
802 default:
803 break;
804 }
805 return QAccessibleRangeControl::doDefaultAction( control );
806}
807
808/*!
809 \class QAccessibleScrollBar qaccessiblewidget.h
810 \brief The QAccessibleScrollBar class implements the QAccessibleInterface for scroll bars.
811*/
812
813/*!
814 Constructs a QAccessibleScrollBar object for \a o.
815 \a name, \a description, \a help, \a defAction and \a accelerator
816 are propagated to the QAccessibleRangeControl constructor.
817*/
818QAccessibleScrollBar::QAccessibleScrollBar( QObject *o, QString name,
819 QString description, QString help, QString defAction, QString accelerator )
820: QAccessibleRangeControl( o, ScrollBar, name, description, help, defAction, accelerator )
821{
822 Q_ASSERT( o->inherits("QScrollBar" ) );
823}
824
825/*! Returns the scroll bar. */
826QScrollBar *QAccessibleScrollBar::scrollBar() const
827{
828 return (QScrollBar*)widget();
829}
830
831/*! \reimp */
832int QAccessibleScrollBar::controlAt( int x, int y ) const
833{
834 for ( int i = 1; i <= childCount(); i++ ) {
835 if ( rect(i).contains( x,y ) )
836 return i;
837 }
838 return 0;
839}
840
841/*! \reimp */
842QRect QAccessibleScrollBar::rect( int control ) const
843{
844 QRect rect;
845 QRect srect = scrollBar()->sliderRect();
846 int sz = scrollBar()->style().pixelMetric( QStyle::PM_ScrollBarExtent, scrollBar() );
847 switch ( control ) {
848 case 1:
849 if ( scrollBar()->orientation() == Vertical )
850 rect = QRect( 0, 0, sz, sz );
851 else
852 rect = QRect( 0, 0, sz, sz );
853 break;
854 case 2:
855 if ( scrollBar()->orientation() == Vertical )
856 rect = QRect( 0, sz, sz, srect.y() - sz );
857 else
858 rect = QRect( sz, 0, srect.x() - sz, sz );
859 break;
860 case 3:
861 rect = srect;
862 break;
863 case 4:
864 if ( scrollBar()->orientation() == Vertical )
865 rect = QRect( 0, srect.bottom(), sz, scrollBar()->rect().height() - srect.bottom() - sz );
866 else
867 rect = QRect( srect.right(), 0, scrollBar()->rect().width() - srect.right() - sz, sz ) ;
868 break;
869 case 5:
870 if ( scrollBar()->orientation() == Vertical )
871 rect = QRect( 0, scrollBar()->rect().height() - sz, sz, sz );
872 else
873 rect = QRect( scrollBar()->rect().width() - sz, 0, sz, sz );
874 break;
875 default:
876 return QAccessibleRangeControl::rect( control );
877 }
878
879 QPoint tp = scrollBar()->mapToGlobal( QPoint( 0,0 ) );
880 return QRect( tp.x() + rect.x(), tp.y() + rect.y(), rect.width(), rect.height() );
881}
882
883/*! \reimp */
884int QAccessibleScrollBar::navigate( NavDirection direction, int startControl ) const
885{
886 if ( direction != NavFirstChild && direction != NavLastChild && direction != NavFocusChild && !startControl )
887 return QAccessibleRangeControl::navigate( direction, startControl );
888
889 switch ( direction ) {
890 case NavFirstChild:
891 return 1;
892 case NavLastChild:
893 return 5;
894 case NavNext:
895 return startControl == childCount() ? -1 : startControl + 1;
896 case NavDown:
897 if ( scrollBar()->orientation() == Horizontal )
898 break;
899 return startControl == childCount() ? -1 : startControl + 1;
900 case NavRight:
901 if ( scrollBar()->orientation() == Vertical )
902 break;
903 return startControl == childCount() ? -1 : startControl + 1;
904 case NavPrevious:
905 return startControl == 1 ? -1 : startControl - 1;
906 case NavUp:
907 if ( scrollBar()->orientation() == Horizontal )
908 break;
909 return startControl == 1 ? -1 : startControl - 1;
910 case NavLeft:
911 if ( scrollBar()->orientation() == Vertical )
912 break;
913 return startControl == 1 ? -1 : startControl - 1;
914 default:
915 break;
916 }
917
918 return -1;
919}
920
921/*! \reimp */
922int QAccessibleScrollBar::childCount() const
923{
924 return 5;
925}
926
927/*! \reimp */
928QRESULT QAccessibleScrollBar::queryChild( int /*control*/, QAccessibleInterface **iface ) const
929{
930 *iface = 0;
931 return QS_FALSE;
932}
933
934/*! \reimp */
935QString QAccessibleScrollBar::text( Text t, int control ) const
936{
937 switch ( t ) {
938 case Value:
939 if ( control && control != 3 )
940 return QString::null;
941 break;
942 case Name:
943 switch ( control ) {
944 case 1:
945 return QScrollBar::tr("Line up");
946 case 2:
947 return QScrollBar::tr("Page up");
948 case 3:
949 return QScrollBar::tr("Position");
950 case 4:
951 return QScrollBar::tr("Page down");
952 case 5:
953 return QScrollBar::tr("Line down");
954 }
955 break;
956 case DefaultAction:
957 if ( control != 3 )
958 return QScrollBar::tr("Press");
959 break;
960 default:
961 break;
962
963 }
964 return QAccessibleRangeControl::text( t, control );
965}
966
967/*! \reimp */
968QAccessible::Role QAccessibleScrollBar::role( int control ) const
969{
970 switch ( control ) {
971 case 1:
972 case 2:
973 return PushButton;
974 case 3:
975 return Indicator;
976 case 4:
977 case 5:
978 return PushButton;
979 default:
980 return ScrollBar;
981 }
982}
983
984/*! \reimp */
985bool QAccessibleScrollBar::doDefaultAction( int control )
986{
987 switch ( control ) {
988 case 1:
989 scrollBar()->subtractLine();
990 return TRUE;
991 case 2:
992 scrollBar()->subtractPage();
993 return TRUE;
994 case 4:
995 scrollBar()->addPage();
996 return TRUE;
997 case 5:
998 scrollBar()->addLine();
999 return TRUE;
1000 default:
1001 return FALSE;
1002 }
1003}
1004
1005/*!
1006 \class QAccessibleSlider qaccessiblewidget.h
1007 \brief The QAccessibleScrollBar class implements the QAccessibleInterface for sliders.
1008*/
1009
1010/*!
1011 Constructs a QAccessibleScrollBar object for \a o.
1012 \a name, \a description, \a help, \a defAction and \a accelerator
1013 are propagated to the QAccessibleRangeControl constructor.
1014*/
1015QAccessibleSlider::QAccessibleSlider( QObject *o, QString name,
1016 QString description, QString help, QString defAction, QString accelerator )
1017: QAccessibleRangeControl( o, ScrollBar, name, description, help, defAction, accelerator )
1018{
1019 Q_ASSERT( o->inherits("QSlider" ) );
1020}
1021
1022/*! Returns the slider. */
1023QSlider *QAccessibleSlider::slider() const
1024{
1025 return (QSlider*)widget();
1026}
1027
1028/*! \reimp */
1029int QAccessibleSlider::controlAt( int x, int y ) const
1030{
1031 for ( int i = 1; i <= childCount(); i++ ) {
1032 if ( rect(i).contains( x,y ) )
1033 return i;
1034 }
1035 return 0;
1036}
1037
1038/*! \reimp */
1039QRect QAccessibleSlider::rect( int control ) const
1040{
1041 QRect rect;
1042 QRect srect = slider()->sliderRect();
1043 switch ( control ) {
1044 case 1:
1045 if ( slider()->orientation() == Vertical )
1046 rect = QRect( 0, 0, slider()->width(), srect.y() );
1047 else
1048 rect = QRect( 0, 0, srect.x(), slider()->height() );
1049 break;
1050 case 2:
1051 rect = srect;
1052 break;
1053 case 3:
1054 if ( slider()->orientation() == Vertical )
1055 rect = QRect( 0, srect.y() + srect.height(), slider()->width(), slider()->height()- srect.y() - srect.height() );
1056 else
1057 rect = QRect( srect.x() + srect.width(), 0, slider()->width() - srect.x() - srect.width(), slider()->height() );
1058 break;
1059 default:
1060 return QAccessibleRangeControl::rect( control );
1061 }
1062
1063 QPoint tp = slider()->mapToGlobal( QPoint( 0,0 ) );
1064 return QRect( tp.x() + rect.x(), tp.y() + rect.y(), rect.width(), rect.height() );
1065}
1066
1067/*! \reimp */
1068int QAccessibleSlider::navigate( NavDirection direction, int startControl ) const
1069{
1070 if ( direction != NavFirstChild && direction != NavLastChild && direction != NavFocusChild && !startControl )
1071 return QAccessibleRangeControl::navigate( direction, startControl );
1072
1073 switch ( direction ) {
1074 case NavFirstChild:
1075 return 1;
1076 case NavLastChild:
1077 return childCount();
1078 case NavNext:
1079 return startControl == childCount() ? -1 : startControl + 1;
1080 case NavDown:
1081 if ( slider()->orientation() == Horizontal )
1082 break;
1083 return startControl == childCount() ? -1 : startControl + 1;
1084 case NavRight:
1085 if ( slider()->orientation() == Vertical )
1086 break;
1087 return startControl == childCount() ? -1 : startControl + 1;
1088 case NavPrevious:
1089 return startControl == 1 ? -1 : startControl - 1;
1090 case NavUp:
1091 if ( slider()->orientation() == Horizontal )
1092 break;
1093 return startControl == 1 ? -1 : startControl - 1;
1094 case NavLeft:
1095 if ( slider()->orientation() == Vertical )
1096 break;
1097 return startControl == 1 ? -1 : startControl - 1;
1098 default:
1099 break;
1100 }
1101
1102 return -1;
1103}
1104
1105/*! \reimp */
1106int QAccessibleSlider::childCount() const
1107{
1108 return 3;
1109}
1110
1111/*! \reimp */
1112QRESULT QAccessibleSlider::queryChild( int /*control*/, QAccessibleInterface **iface ) const
1113{
1114 *iface = 0;
1115 return QS_FALSE;
1116}
1117
1118/*! \reimp */
1119QString QAccessibleSlider::text( Text t, int control ) const
1120{
1121 switch ( t ) {
1122 case Value:
1123 if ( control && control != 2 )
1124 return QString::null;
1125 break;
1126 case Name:
1127 switch ( control ) {
1128 case 1:
1129 return QSlider::tr("Page up");
1130 case 2:
1131 return QSlider::tr("Position");
1132 case 3:
1133 return QSlider::tr("Page down");
1134 }
1135 break;
1136 case DefaultAction:
1137 if ( control != 2 )
1138 return QSlider::tr("Press");
1139 break;
1140 default:
1141 break;
1142 }
1143 return QAccessibleRangeControl::text( t, control );
1144}
1145
1146/*! \reimp */
1147QAccessible::Role QAccessibleSlider::role( int control ) const
1148{
1149 switch ( control ) {
1150 case 1:
1151 return PushButton;
1152 case 2:
1153 return Indicator;
1154 case 3:
1155 return PushButton;
1156 default:
1157 return Slider;
1158 }
1159}
1160
1161/*! \reimp */
1162bool QAccessibleSlider::doDefaultAction( int control )
1163{
1164 switch ( control ) {
1165 case 1:
1166 slider()->subtractLine();
1167 return TRUE;
1168 case 3:
1169 slider()->addLine();
1170 return TRUE;
1171 default:
1172 return FALSE;
1173 }
1174}
1175
1176
1177/*!
1178 \class QAccessibleText qaccessiblewidget.h
1179 \brief The QAccessibleText class implements the QAccessibleInterface for widgets with editable text.
1180*/
1181
1182/*!
1183 Constructs a QAccessibleText object for \a o.
1184 \a role, \a name, \a description, \a help, \a defAction and \a accelerator
1185 are propagated to the QAccessibleWidget constructor.
1186*/
1187QAccessibleText::QAccessibleText( QObject *o, Role role, QString name, QString description, QString help, QString defAction, QString accelerator )
1188: QAccessibleWidget( o, role, name, description, QString::null, help, defAction, accelerator )
1189{
1190}
1191
1192/*! \reimp */
1193QString QAccessibleText::text( Text t, int control ) const
1194{
1195 QString str = QAccessibleWidget::text( t, control );
1196 if ( !!str )
1197 return str;
1198 switch ( t ) {
1199 case Name:
1200 return stripAmp( buddyString( widget() ) );
1201 case Accelerator:
1202 str = hotKey( buddyString( widget() ) );
1203 if ( !!str )
1204 return "Alt + "+str;
1205 break;
1206 case Value:
1207 if ( widget()->inherits( "QLineEdit" ) )
1208 return ((QLineEdit*)widget())->text();
1209 break;
1210 default:
1211 break;
1212 }
1213 return str;
1214}
1215
1216/*! \reimp */
1217void QAccessibleText::setText(Text t, int control, const QString &text)
1218{
1219 if (t != Value || !widget()->inherits("QLineEdit") || control) {
1220 QAccessibleWidget::setText(t, control, text);
1221 return;
1222 }
1223 ((QLineEdit*)widget())->setText(text);
1224}
1225
1226/*! \reimp */
1227QAccessible::State QAccessibleText::state( int control ) const
1228{
1229 int state = QAccessibleWidget::state( control );
1230
1231 if ( widget()->inherits( "QLineEdit" ) ) {
1232 QLineEdit *l = (QLineEdit*)widget();
1233 if ( l->isReadOnly() )
1234 state |= ReadOnly;
1235 if ( l->echoMode() == QLineEdit::Password )
1236 state |= Protected;
1237 state |= Selectable;
1238 if ( l->hasSelectedText() )
1239 state |= Selected;
1240 }
1241
1242 return (State)state;
1243}
1244
1245/*!
1246 \class QAccessibleDisplay qaccessiblewidget.h
1247 \brief The QAccessibleDisplay class implements the QAccessibleInterface for widgets that display static information.
1248*/
1249
1250/*!
1251 Constructs a QAccessibleDisplay object for \a o.
1252 \a role, \a description, \a value, \a help, \a defAction and \a accelerator
1253 are propagated to the QAccessibleWidget constructor.
1254*/
1255QAccessibleDisplay::QAccessibleDisplay( QObject *o, Role role, QString description, QString value, QString help, QString defAction, QString accelerator )
1256: QAccessibleWidget( o, role, QString::null, description, value, help, defAction, accelerator )
1257{
1258}
1259
1260/*! \reimp */
1261QAccessible::Role QAccessibleDisplay::role( int control ) const
1262{
1263 if ( widget()->inherits( "QLabel" ) ) {
1264 QLabel *l = (QLabel*)widget();
1265 if ( l->pixmap() || l->picture() )
1266 return Graphic;
1267#ifndef QT_NO_PICTURE
1268 if ( l->picture() )
1269 return Graphic;
1270#endif
1271#ifndef QT_NO_MOVIE
1272 if ( l->movie() )
1273 return Animation;
1274#endif
1275 }
1276 return QAccessibleWidget::role( control );
1277}
1278
1279/*! \reimp */
1280QString QAccessibleDisplay::text( Text t, int control ) const
1281{
1282 QString str = QAccessibleWidget::text( t, control );
1283 if ( !!str )
1284 return str;
1285
1286 switch ( t ) {
1287 case Name:
1288 if ( widget()->inherits( "QLabel" ) ) {
1289 return stripAmp( ((QLabel*)widget())->text() );
1290 } else if ( widget()->inherits( "QLCDNumber" ) ) {
1291 QLCDNumber *l = (QLCDNumber*)widget();
1292 if ( l->numDigits() )
1293 return QString::number( l->value() );
1294 return QString::number( l->intValue() );
1295 } else if ( widget()->inherits( "QGroupBox" ) ) {
1296 return stripAmp( ((QGroupBox*)widget())->title() );
1297 }
1298 break;
1299 default:
1300 break;
1301 }
1302 return str;
1303}
1304
1305
1306/*!
1307 \class QAccessibleHeader qaccessiblewidget.h
1308 \brief The QAccessibleHeader class implements the QAccessibleInterface for header widgets.
1309*/
1310
1311/*!
1312 Constructs a QAccessibleHeader object for \a o.
1313 \a role, \a description, \a value, \a help, \a defAction and \a accelerator
1314 are propagated to the QAccessibleWidget constructor.
1315*/
1316QAccessibleHeader::QAccessibleHeader( QObject *o, QString description,
1317 QString value, QString help, QString defAction, QString accelerator )
1318 : QAccessibleWidget( o, NoRole, description, value, help, defAction, accelerator )
1319{
1320 Q_ASSERT(widget()->inherits("QHeader"));
1321}
1322
1323/*! Returns the QHeader. */
1324QHeader *QAccessibleHeader::header() const
1325{
1326 return (QHeader *)widget();
1327}
1328
1329/*! \reimp */
1330int QAccessibleHeader::controlAt( int x, int y ) const
1331{
1332 QPoint point = header()->mapFromGlobal( QPoint( x, y ) );
1333 for ( int i = 0; i < header()->count(); i++ ) {
1334 if ( header()->sectionRect( i ).contains( point ) )
1335 return i+1;
1336 }
1337 return -1;
1338}
1339
1340/*! \reimp */
1341QRect QAccessibleHeader::rect( int control ) const
1342{
1343 QPoint zero = header()->mapToGlobal( QPoint ( 0,0 ) );
1344 QRect sect = header()->sectionRect( control - 1 );
1345 return QRect( sect.x() + zero.x(), sect.y() + zero.y(), sect.width(), sect.height() );
1346}
1347
1348/*! \reimp */
1349int QAccessibleHeader::navigate( NavDirection direction, int startControl ) const
1350{
1351 if ( direction != NavFirstChild && direction != NavLastChild && direction != NavFocusChild && !startControl )
1352 return QAccessibleWidget::navigate( direction, startControl );
1353
1354 int count = header()->count();
1355 switch ( direction ) {
1356 case NavFirstChild:
1357 return 1;
1358 case NavLastChild:
1359 return count;
1360 case NavNext:
1361 return startControl + 1 > count ? -1 : startControl + 1;
1362 case NavPrevious:
1363 return startControl - 1 < 1 ? -1 : startControl - 1;
1364 case NavUp:
1365 if ( header()->orientation() == Vertical )
1366 return startControl - 1 < 1 ? -1 : startControl - 1;
1367 return -1;
1368 case NavDown:
1369 if ( header()->orientation() == Vertical )
1370 return startControl + 1 > count ? -1 : startControl + 1;
1371 break;
1372 case NavLeft:
1373 if ( header()->orientation() == Horizontal )
1374 return startControl - 1 < 1 ? -1 : startControl - 1;
1375 break;
1376 case NavRight:
1377 if ( header()->orientation() == Horizontal )
1378 return startControl + 1 > count ? -1 : startControl + 1;
1379 break;
1380 default:
1381 break;
1382 }
1383 return -1;
1384}
1385
1386/*! \reimp */
1387int QAccessibleHeader::childCount() const
1388{
1389 return header()->count();
1390}
1391
1392/*! \reimp */
1393QRESULT QAccessibleHeader::queryChild( int /*control*/, QAccessibleInterface **iface ) const
1394{
1395 *iface = 0;
1396 return QS_FALSE;
1397}
1398
1399/*! \reimp */
1400QString QAccessibleHeader::text( Text t, int control ) const
1401{
1402 QString str = QAccessibleWidget::text( t, control );
1403 if ( !!str )
1404 return str;
1405
1406 switch ( t ) {
1407 case Name:
1408 return header()->label( control - 1 );
1409 default:
1410 break;
1411 }
1412 return str;
1413}
1414
1415/*! \reimp */
1416QAccessible::Role QAccessibleHeader::role( int /*control*/ ) const
1417{
1418 if ( header()->orientation() == Qt::Horizontal )
1419 return ColumnHeader;
1420 else
1421 return RowHeader;
1422}
1423
1424/*! \reimp */
1425QAccessible::State QAccessibleHeader::state( int control ) const
1426{
1427 return QAccessibleWidget::state( control );
1428}
1429
1430
1431/*!
1432 \class QAccessibleTabBar qaccessiblewidget.h
1433 \brief The QAccessibleTabBar class implements the QAccessibleInterface for tab bars.
1434*/
1435
1436/*!
1437 Constructs a QAccessibleTabBar object for \a o.
1438 \a role, \a description, \a value, \a help, \a defAction and \a accelerator
1439 are propagated to the QAccessibleWidget constructor.
1440*/
1441QAccessibleTabBar::QAccessibleTabBar( QObject *o, QString description,
1442 QString value, QString help, QString defAction, QString accelerator )
1443 : QAccessibleWidget( o, NoRole, description, value, help, defAction, accelerator )
1444{
1445 Q_ASSERT(widget()->inherits("QTabBar"));
1446}
1447
1448/*! Returns the QHeader. */
1449QTabBar *QAccessibleTabBar::tabBar() const
1450{
1451 return (QTabBar*)widget();
1452}
1453
1454/*! \reimp */
1455int QAccessibleTabBar::controlAt( int x, int y ) const
1456{
1457 int wc = QAccessibleWidget::controlAt( x, y );
1458 if ( wc )
1459 return wc + tabBar()->count();
1460
1461 QPoint tp = tabBar()->mapFromGlobal( QPoint( x,y ) );
1462 QTab *tab = tabBar()->selectTab( tp );
1463 return tabBar()->indexOf( tab->identifier() ) + 1;
1464}
1465
1466/*! \reimp */
1467QRect QAccessibleTabBar::rect( int control ) const
1468{
1469 if ( !control )
1470 return QAccessibleWidget::rect( 0 );
1471 if ( control > tabBar()->count() ) {
1472 QAccessibleInterface *iface;
1473 QAccessibleWidget::queryChild( control - tabBar()->count(), &iface );
1474 if ( !iface )
1475 return QRect();
1476 return iface->rect( 0 );
1477 }
1478
1479 QTab *tab = tabBar()->tabAt( control - 1 );
1480
1481 QPoint tp = tabBar()->mapToGlobal( QPoint( 0,0 ) );
1482 QRect rec = tab->rect();
1483 return QRect( tp.x() + rec.x(), tp.y() + rec.y(), rec.width(), rec.height() );
1484}
1485
1486/*! \reimp */
1487QRESULT QAccessibleTabBar::queryChild( int /*control*/, QAccessibleInterface **iface ) const
1488{
1489 *iface = 0;
1490 return QS_FALSE;
1491}
1492
1493/*! \reimp */
1494int QAccessibleTabBar::navigate( NavDirection direction, int startControl ) const
1495{
1496 if ( direction != NavFirstChild && direction != NavLastChild && direction != NavFocusChild && !startControl )
1497 return QAccessibleWidget::navigate( direction, startControl );
1498
1499 switch ( direction ) {
1500 case NavFirstChild:
1501 return 1;
1502 break;
1503 case NavLastChild:
1504 return childCount();
1505 break;
1506 case NavNext:
1507 case NavRight:
1508 return startControl + 1 > childCount() ? -1 : startControl + 1;
1509 case NavPrevious:
1510 case NavLeft:
1511 return startControl -1 < 1 ? -1 : startControl - 1;
1512 default:
1513 break;
1514 }
1515 return -1;
1516}
1517
1518/*! \reimp */
1519int QAccessibleTabBar::childCount() const
1520{
1521 int wc = QAccessibleWidget::childCount();
1522 wc += tabBar()->count();
1523 return wc;
1524}
1525
1526/*! \reimp */
1527QString QAccessibleTabBar::text( Text t, int control ) const
1528{
1529 QString str = QAccessibleWidget::text( t, control );
1530 if ( !!str )
1531 return str;
1532
1533 if ( !control )
1534 return QAccessibleWidget::text( t, control );
1535 if ( control > tabBar()->count() ) {
1536 QAccessibleInterface *iface;
1537 QAccessibleWidget::queryChild( control - tabBar()->count(), &iface );
1538 if ( !iface )
1539 return QAccessibleWidget::text( t, 0 );
1540 return iface->text( t, 0 );
1541 }
1542
1543 QTab *tab = tabBar()->tabAt( control - 1 );
1544 if ( !tab )
1545 return QAccessibleWidget::text( t, 0 );
1546
1547 switch ( t ) {
1548 case Name:
1549 return stripAmp( tab->text() );
1550 case DefaultAction:
1551 return QTabBar::tr( "Switch" );
1552 default:
1553 break;
1554 }
1555 return str;
1556}
1557
1558/*! \reimp */
1559QAccessible::Role QAccessibleTabBar::role( int control ) const
1560{
1561 if ( !control )
1562 return PageTabList;
1563 if ( control > tabBar()->count() ) {
1564 QAccessibleInterface *iface;
1565 QAccessibleWidget::queryChild( control - tabBar()->count(), &iface );
1566 if ( !iface )
1567 return QAccessibleWidget::role( 0 );
1568 return iface->role( 0 );
1569 }
1570
1571 return PageTab;
1572}
1573
1574/*! \reimp */
1575QAccessible::State QAccessibleTabBar::state( int control ) const
1576{
1577 int st = QAccessibleWidget::state( 0 );
1578
1579 if ( !control )
1580 return (State)st;
1581 if ( control > tabBar()->count() ) {
1582 QAccessibleInterface *iface;
1583 QAccessibleWidget::queryChild( control - tabBar()->count(), &iface );
1584 if ( !iface )
1585 return (State)st;
1586 return iface->state( 0 );
1587 }
1588
1589 QTab *tab = tabBar()->tabAt( control - 1 );
1590 if ( !tab )
1591 return (State)st;
1592
1593 if ( !tab->isEnabled() )
1594 st |= Unavailable;
1595 else
1596 st |= Selectable;
1597
1598 if ( tabBar()->currentTab() == tab->identifier() )
1599 st |= Selected;
1600
1601 return (State)st;
1602}
1603
1604/*! \reimp */
1605bool QAccessibleTabBar::doDefaultAction( int control )
1606{
1607 if ( !control )
1608 return FALSE;
1609 if ( control > tabBar()->count() ) {
1610 QAccessibleInterface *iface;
1611 QAccessibleWidget::queryChild( control - tabBar()->count(), &iface );
1612 if ( !iface )
1613 return FALSE;
1614 return iface->doDefaultAction( 0 );
1615 }
1616
1617 QTab *tab = tabBar()->tabAt( control - 1 );
1618 if ( !tab || !tab->isEnabled() )
1619 return FALSE;
1620 tabBar()->setCurrentTab( tab );
1621 return TRUE;
1622}
1623
1624/*! \reimp */
1625bool QAccessibleTabBar::setSelected( int control, bool on, bool extend )
1626{
1627 if ( !control || !on || extend || control > tabBar()->count() )
1628 return FALSE;
1629
1630 QTab *tab = tabBar()->tabAt( control - 1 );
1631 if ( !tab || !tab->isEnabled() )
1632 return FALSE;
1633 tabBar()->setCurrentTab( tab );
1634 return TRUE;
1635}
1636
1637/*! \reimp */
1638void QAccessibleTabBar::clearSelection()
1639{
1640}
1641
1642/*! \reimp */
1643QMemArray<int> QAccessibleTabBar::selection() const
1644{
1645 QMemArray<int> array( 1 );
1646 array.at(0) = tabBar()->indexOf( tabBar()->currentTab() ) + 1;
1647
1648 return array;
1649}
1650
1651/*!
1652 \class QAccessibleComboBox qaccessiblewidget.h
1653 \brief The QAccessibleComboBox class implements the QAccessibleInterface for editable and read-only combo boxes.
1654*/
1655
1656
1657/*!
1658 Constructs a QAccessibleComboBox object for \a o.
1659*/
1660QAccessibleComboBox::QAccessibleComboBox( QObject *o )
1661: QAccessibleWidget( o, ComboBox )
1662{
1663 Q_ASSERT(o->inherits("QComboBox"));
1664}
1665
1666/*!
1667 Returns the combo box.
1668*/
1669QComboBox *QAccessibleComboBox::comboBox() const
1670{
1671 return (QComboBox*)object();
1672}
1673
1674/*! \reimp */
1675int QAccessibleComboBox::controlAt( int x, int y ) const
1676{
1677 for ( int i = childCount(); i >= 0; --i ) {
1678 if ( rect( i ).contains( x, y ) )
1679 return i;
1680 }
1681 return -1;
1682}
1683
1684/*! \reimp */
1685QRect QAccessibleComboBox::rect( int control ) const
1686{
1687 QPoint tp;
1688 QRect r;
1689
1690 switch( control ) {
1691 case 1:
1692 if ( comboBox()->editable() ) {
1693 tp = comboBox()->lineEdit()->mapToGlobal( QPoint( 0,0 ) );
1694 r = comboBox()->lineEdit()->rect();
1695 } else {
1696 tp = comboBox()->mapToGlobal( QPoint( 0,0 ) );
1697 r = comboBox()->style().querySubControlMetrics( QStyle::CC_ComboBox, comboBox(), QStyle::SC_ComboBoxEditField );
1698 }
1699 break;
1700 case 2:
1701 tp = comboBox()->mapToGlobal( QPoint( 0,0 ) );
1702 r = comboBox()->style().querySubControlMetrics( QStyle::CC_ComboBox, comboBox(), QStyle::SC_ComboBoxArrow );
1703 break;
1704 default:
1705 return QAccessibleWidget::rect( control );
1706 }
1707 return QRect( tp.x() + r.x(), tp.y() + r.y(), r.width(), r.height() );
1708}
1709
1710/*! \reimp */
1711int QAccessibleComboBox::navigate( NavDirection direction, int startControl ) const
1712{
1713 if ( direction != NavFirstChild && direction != NavLastChild && direction != NavFocusChild && !startControl )
1714 return QAccessibleWidget::navigate( direction, startControl );
1715
1716 switch ( direction ) {
1717 case NavFirstChild:
1718 return 1;
1719 break;
1720 case NavLastChild:
1721 return childCount();
1722 break;
1723 case NavNext:
1724 case NavRight:
1725 return startControl + 1 > childCount() ? -1 : startControl + 1;
1726 case NavPrevious:
1727 case NavLeft:
1728 return startControl -1 < 1 ? -1 : startControl - 1;
1729 default:
1730 break;
1731 }
1732 return -1;
1733}
1734
1735/*! \reimp */
1736int QAccessibleComboBox::childCount() const
1737{
1738 return 2;
1739}
1740
1741/*! \reimp */
1742QRESULT QAccessibleComboBox::queryChild( int /*control*/, QAccessibleInterface **iface ) const
1743{
1744 *iface = 0;
1745 return QS_FALSE;
1746}
1747
1748/*! \reimp */
1749QString QAccessibleComboBox::text( Text t, int control ) const
1750{
1751 QString str;
1752
1753 switch ( t ) {
1754 case Name:
1755 if ( control < 2 )
1756 return stripAmp( buddyString( comboBox() ) );
1757 return QComboBox::tr("Open");
1758 case Accelerator:
1759 if ( control < 2 ) {
1760 str = hotKey( buddyString( comboBox() ) );
1761 if ( !!str )
1762 return "Alt + " + str;
1763 return str;
1764 }
1765 return QComboBox::tr("Alt + Down Arrow" );
1766 case Value:
1767 if ( control < 2 ) {
1768 if ( comboBox()->editable() )
1769 return comboBox()->lineEdit()->text();
1770 return comboBox()->currentText();
1771 }
1772 break;
1773 case DefaultAction:
1774 if ( control == 2 )
1775 return QComboBox::tr("Open");
1776 break;
1777 default:
1778 str = QAccessibleWidget::text( t, 0 );
1779 break;
1780 }
1781 return str;
1782}
1783
1784/*! \reimp */
1785QAccessible::Role QAccessibleComboBox::role( int control ) const
1786{
1787 switch ( control ) {
1788 case 0:
1789 return ComboBox;
1790 case 1:
1791 if ( comboBox()->editable() )
1792 return EditableText;
1793 return StaticText;
1794 case 2:
1795 return PushButton;
1796 default:
1797 return List;
1798 }
1799}
1800
1801/*! \reimp */
1802QAccessible::State QAccessibleComboBox::state( int /*control*/ ) const
1803{
1804 return QAccessibleWidget::state( 0 );
1805}
1806
1807/*! \reimp */
1808bool QAccessibleComboBox::doDefaultAction( int control )
1809{
1810 if ( control != 2 )
1811 return FALSE;
1812 comboBox()->popup();
1813 return TRUE;
1814}
1815
1816/*!
1817 \class QAccessibleTitleBar qaccessiblewidget.h
1818 \brief The QAccessibleTitleBar class implements the QAccessibleInterface for title bars.
1819*/
1820
1821/*!
1822 Constructs a QAccessibleComboBox object for \a o.
1823*/
1824QAccessibleTitleBar::QAccessibleTitleBar( QObject *o )
1825: QAccessibleWidget( o, ComboBox )
1826{
1827 Q_ASSERT(o->inherits("QTitleBar"));
1828}
1829
1830/*!
1831 Returns the title bar.
1832*/
1833QTitleBar *QAccessibleTitleBar::titleBar() const
1834{
1835 return (QTitleBar*)object();
1836}
1837
1838/*! \reimp */
1839int QAccessibleTitleBar::controlAt( int x, int y ) const
1840{
1841 int ctrl = titleBar()->style().querySubControl( QStyle::CC_TitleBar, titleBar(), titleBar()->mapFromGlobal( QPoint( x,y ) ) );
1842
1843 switch ( ctrl )
1844 {
1845 case QStyle::SC_TitleBarSysMenu:
1846 return 1;
1847 case QStyle::SC_TitleBarLabel:
1848 return 2;
1849 case QStyle::SC_TitleBarMinButton:
1850 return 3;
1851 case QStyle::SC_TitleBarMaxButton:
1852 return 4;
1853 case QStyle::SC_TitleBarCloseButton:
1854 return 5;
1855 default:
1856 break;
1857 }
1858 return 0;
1859}
1860
1861/*! \reimp */
1862QRect QAccessibleTitleBar::rect( int control ) const
1863{
1864 if ( !control )
1865 return QAccessibleWidget::rect( control );
1866
1867 QRect r;
1868 switch ( control ) {
1869 case 1:
1870 r = titleBar()->style().querySubControlMetrics( QStyle::CC_TitleBar, titleBar(), QStyle::SC_TitleBarSysMenu );
1871 break;
1872 case 2:
1873 r = titleBar()->style().querySubControlMetrics( QStyle::CC_TitleBar, titleBar(), QStyle::SC_TitleBarLabel );
1874 break;
1875 case 3:
1876 r = titleBar()->style().querySubControlMetrics( QStyle::CC_TitleBar, titleBar(), QStyle::SC_TitleBarMinButton );
1877 break;
1878 case 4:
1879 r = titleBar()->style().querySubControlMetrics( QStyle::CC_TitleBar, titleBar(), QStyle::SC_TitleBarMaxButton );
1880 break;
1881 case 5:
1882 r = titleBar()->style().querySubControlMetrics( QStyle::CC_TitleBar, titleBar(), QStyle::SC_TitleBarCloseButton );
1883 break;
1884 default:
1885 break;
1886 }
1887
1888 QPoint tp = titleBar()->mapToGlobal( QPoint( 0,0 ) );
1889 return QRect( tp.x() + r.x(), tp.y() + r.y(), r.width(), r.height() );
1890}
1891
1892/*! \reimp */
1893int QAccessibleTitleBar::navigate( NavDirection direction, int startControl ) const
1894{
1895 if ( direction != NavFirstChild && direction != NavLastChild && direction != NavFocusChild && !startControl )
1896 return QAccessibleWidget::navigate( direction, startControl );
1897
1898 switch ( direction ) {
1899 case NavFirstChild:
1900 return 1;
1901 break;
1902 case NavLastChild:
1903 return childCount();
1904 break;
1905 case NavNext:
1906 case NavRight:
1907 return startControl + 1 > childCount() ? -1 : startControl + 1;
1908 case NavPrevious:
1909 case NavLeft:
1910 return startControl -1 < 1 ? -1 : startControl - 1;
1911 default:
1912 break;
1913 }
1914 return -1;
1915}
1916
1917/*! \reimp */
1918int QAccessibleTitleBar::childCount() const
1919{
1920 return 5;
1921}
1922
1923/*! \reimp */
1924QRESULT QAccessibleTitleBar::queryChild( int /*control*/, QAccessibleInterface **iface ) const
1925{
1926 *iface = 0;
1927 return QS_FALSE;
1928}
1929
1930/*! \reimp */
1931QString QAccessibleTitleBar::text( Text t, int control ) const
1932{
1933 QString str = QAccessibleWidget::text( t, control );
1934 if ( !!str )
1935 return str;
1936
1937 switch ( t ) {
1938 case Name:
1939 switch ( control ) {
1940 case 1:
1941 return QTitleBar::tr("System");
1942 case 3:
1943 if ( titleBar()->window()->isMinimized() )
1944 return QTitleBar::tr("Restore up");
1945 return QTitleBar::tr("Minimize");
1946 case 4:
1947 if ( titleBar()->window()->isMaximized() )
1948 return QTitleBar::tr("Restore down");
1949 return QTitleBar::tr("Maximize");
1950 case 5:
1951 return QTitleBar::tr("Close");
1952 default:
1953 break;
1954 }
1955 break;
1956 case Value:
1957 if ( !control || control == 2 )
1958 return titleBar()->window()->caption();
1959 break;
1960 case DefaultAction:
1961 if ( control > 2 )
1962 return QTitleBar::tr("Press");
1963 break;
1964 case Description:
1965 switch ( control ) {
1966 case 1:
1967 return QTitleBar::tr("Contains commands to manipulate the window");
1968 case 3:
1969 if ( titleBar()->window()->isMinimized() )
1970 return QTitleBar::tr("Puts a minimized back to normal");
1971 return QTitleBar::tr("Moves the window out of the way");
1972 case 4:
1973 if ( titleBar()->window()->isMaximized() )
1974 return QTitleBar::tr("Puts a maximized window back to normal");
1975 return QTitleBar::tr("Makes the window full screen");
1976 case 5:
1977 return QTitleBar::tr("Closes the window");
1978 default:
1979 return QTitleBar::tr("Displays the name of the window and contains controls to manipulate it");
1980 }
1981 default:
1982 break;
1983 }
1984 return str;
1985}
1986
1987/*! \reimp */
1988QAccessible::Role QAccessibleTitleBar::role( int control ) const
1989{
1990 switch ( control )
1991 {
1992 case 1:
1993 case 3:
1994 case 4:
1995 case 5:
1996 return PushButton;
1997 default:
1998 return TitleBar;
1999 }
2000}
2001
2002/*! \reimp */
2003QAccessible::State QAccessibleTitleBar::state( int control ) const
2004{
2005 return QAccessibleWidget::state( control );
2006}
2007
2008/*! \reimp */
2009bool QAccessibleTitleBar::doDefaultAction( int control )
2010{
2011 switch ( control ) {
2012 case 3:
2013 if ( titleBar()->window()->isMinimized() )
2014 titleBar()->window()->showNormal();
2015 else
2016 titleBar()->window()->showMinimized();
2017 return TRUE;
2018 case 4:
2019 if ( titleBar()->window()->isMaximized() )
2020 titleBar()->window()->showNormal();
2021 else
2022 titleBar()->window()->showMaximized();
2023 return TRUE;
2024 case 5:
2025 titleBar()->window()->close();
2026 return TRUE;
2027 default:
2028 break;
2029 }
2030 return FALSE;
2031}
2032
2033
2034/*!
2035 \class QAccessibleViewport qaccessiblewidget.h
2036 \brief The QAccessibleViewport class hides the viewport of scrollviews for accessibility.
2037 \internal
2038*/
2039
2040QAccessibleViewport::QAccessibleViewport( QObject *o, QObject *sv )
2041 : QAccessibleWidget( o )
2042{
2043 Q_ASSERT( sv->inherits("QScrollView") );
2044 scrollview = (QScrollView*)sv;
2045}
2046
2047QAccessibleScrollView *QAccessibleViewport::scrollView() const
2048{
2049 QAccessibleInterface *iface = 0;
2050 queryAccessibleInterface( scrollview, &iface );
2051 Q_ASSERT(iface);
2052 return (QAccessibleScrollView *)iface;
2053}
2054
2055int QAccessibleViewport::controlAt( int x, int y ) const
2056{
2057 int control = QAccessibleWidget::controlAt( x, y );
2058 if ( control > 0 )
2059 return control;
2060
2061 QPoint p = widget()->mapFromGlobal( QPoint( x,y ) );
2062 return scrollView()->itemAt( p.x(), p.y() );
2063}
2064
2065QRect QAccessibleViewport::rect( int control ) const
2066{
2067 if ( !control )
2068 return QAccessibleWidget::rect( control );
2069 QRect rect = scrollView()->itemRect( control );
2070 QPoint tl = widget()->mapToGlobal( QPoint( 0,0 ) );
2071 return QRect( tl.x() + rect.x(), tl.y() + rect.y(), rect.width(), rect.height() );
2072}
2073
2074int QAccessibleViewport::navigate( NavDirection direction, int startControl ) const
2075{
2076 if ( direction != NavFirstChild && direction != NavLastChild && direction != NavFocusChild && !startControl )
2077 return QAccessibleWidget::navigate( direction, startControl );
2078
2079 // ### call itemUp/Down etc. here
2080 const int items = scrollView()->itemCount();
2081 switch( direction ) {
2082 case NavFirstChild:
2083 return 1;
2084 case NavLastChild:
2085 return items;
2086 case NavNext:
2087 case NavDown:
2088 return startControl + 1 > items ? -1 : startControl + 1;
2089 case NavPrevious:
2090 case NavUp:
2091 return startControl - 1 < 1 ? -1 : startControl - 1;
2092 default:
2093 break;
2094 }
2095
2096 return -1;
2097}
2098
2099int QAccessibleViewport::childCount() const
2100{
2101 int widgets = QAccessibleWidget::childCount();
2102 return widgets ? widgets : scrollView()->itemCount();
2103}
2104
2105QString QAccessibleViewport::text( Text t, int control ) const
2106{
2107 return scrollView()->text( t, control );
2108}
2109
2110bool QAccessibleViewport::doDefaultAction( int control )
2111{
2112 return scrollView()->doDefaultAction( control );
2113}
2114
2115QAccessible::Role QAccessibleViewport::role( int control ) const
2116{
2117 return scrollView()->role( control );
2118}
2119
2120QAccessible::State QAccessibleViewport::state( int control ) const
2121{
2122 return scrollView()->state( control );
2123}
2124
2125bool QAccessibleViewport::setFocus( int control )
2126{
2127 return scrollView()->setFocus( control );
2128}
2129
2130bool QAccessibleViewport::setSelected( int control, bool on, bool extend )
2131{
2132 return scrollView()->setSelected( control, on, extend );
2133}
2134
2135void QAccessibleViewport::clearSelection()
2136{
2137 scrollView()->clearSelection();
2138}
2139
2140QMemArray<int> QAccessibleViewport::selection() const
2141{
2142 return scrollView()->selection();
2143}
2144
2145/*!
2146 \class QAccessibleScrollView qaccessiblewidget.h
2147 \brief The QAccessibleScrollView class implements the QAccessibleInterface for scrolled widgets.
2148*/
2149
2150/*!
2151 Constructs a QAccessibleScrollView object for \a o.
2152 \a role, \a description, \a value, \a help, \a defAction and \a accelerator
2153 are propagated to the QAccessibleWidget constructor.
2154*/
2155QAccessibleScrollView::QAccessibleScrollView( QObject *o, Role role, QString name,
2156 QString description, QString value, QString help, QString defAction, QString accelerator )
2157 : QAccessibleWidget( o, role, name, description, value, help, defAction, accelerator )
2158{
2159}
2160
2161/*! \reimp */
2162QString QAccessibleScrollView::text( Text t, int control ) const
2163{
2164 QString str = QAccessibleWidget::text( t, control );
2165 if ( !!str )
2166 return str;
2167 switch ( t ) {
2168 case Name:
2169 return buddyString( widget() );
2170 default:
2171 break;
2172 }
2173
2174 return str;
2175}
2176
2177/*!
2178 Returns the ID of the item at viewport position \a x, \a y.
2179*/
2180int QAccessibleScrollView::itemAt( int /*x*/, int /*y*/ ) const
2181{
2182 return 0;
2183}
2184
2185/*!
2186 Returns the location of the item with ID \a item in viewport coordinates.
2187*/
2188QRect QAccessibleScrollView::itemRect( int /*item*/ ) const
2189{
2190 return QRect();
2191}
2192
2193/*!
2194 Returns the number of items.
2195*/
2196int QAccessibleScrollView::itemCount() const
2197{
2198 return 0;
2199}
2200
2201/*!
2202 \class QAccessibleListBox qaccessiblewidget.h
2203 \brief The QAccessibleListBox class implements the QAccessibleInterface for list boxes.
2204*/
2205
2206/*!
2207 Constructs a QAccessibleListBox object for \a o.
2208*/
2209QAccessibleListBox::QAccessibleListBox( QObject *o )
2210 : QAccessibleScrollView( o, List )
2211{
2212 Q_ASSERT(widget()->inherits("QListBox"));
2213}
2214
2215/*! Returns the list box. */
2216QListBox *QAccessibleListBox::listBox() const
2217{
2218 return (QListBox*)widget();
2219}
2220
2221/*! \reimp */
2222int QAccessibleListBox::itemAt( int x, int y ) const
2223{
2224 QListBoxItem *item = listBox()->itemAt( QPoint( x, y ) );
2225 return listBox()->index( item ) + 1;
2226}
2227
2228/*! \reimp */
2229QRect QAccessibleListBox::itemRect( int item ) const
2230{
2231 return listBox()->itemRect( listBox()->item( item-1 ) );
2232}
2233
2234/*! \reimp */
2235int QAccessibleListBox::itemCount() const
2236{
2237 return listBox()->count();
2238}
2239
2240/*! \reimp */
2241QString QAccessibleListBox::text( Text t, int control ) const
2242{
2243 if ( !control || t != Name )
2244 return QAccessibleScrollView::text( t, control );
2245
2246 QListBoxItem *item = listBox()->item( control - 1 );
2247 if ( item )
2248 return item->text();
2249 return QString::null;
2250}
2251
2252/*! \reimp */
2253QAccessible::Role QAccessibleListBox::role( int control ) const
2254{
2255 if ( !control )
2256 return QAccessibleScrollView::role( control );
2257 return ListItem;
2258}
2259
2260/*! \reimp */
2261QAccessible::State QAccessibleListBox::state( int control ) const
2262{
2263 int state = QAccessibleScrollView::state( control );
2264 QListBoxItem *item;
2265 if ( !control || !( item = listBox()->item( control - 1 ) ) )
2266 return (State)state;
2267
2268 if ( item->isSelectable() ) {
2269 if ( listBox()->selectionMode() == QListBox::Multi )
2270 state |= MultiSelectable;
2271 else if ( listBox()->selectionMode() == QListBox::Extended )
2272 state |= ExtSelectable;
2273 else if ( listBox()->selectionMode() == QListBox::Single )
2274 state |= Selectable;
2275 if ( item->isSelected() )
2276 state |= Selected;
2277 }
2278 if ( listBox()->focusPolicy() != QWidget::NoFocus ) {
2279 state |= Focusable;
2280 if ( item->isCurrent() )
2281 state |= Focused;
2282 }
2283 if ( !listBox()->itemVisible( item ) )
2284 state |= Invisible;
2285
2286 return (State)state;
2287}
2288
2289/*! \reimp */
2290bool QAccessibleListBox::setFocus( int control )
2291{
2292 bool res = QAccessibleScrollView::setFocus( 0 );
2293 if ( !control || !res )
2294 return res;
2295
2296 QListBoxItem *item = listBox()->item( control -1 );
2297 if ( !item )
2298 return FALSE;
2299 listBox()->setCurrentItem( item );
2300 return TRUE;
2301}
2302
2303/*! \reimp */
2304bool QAccessibleListBox::setSelected( int control, bool on, bool extend )
2305{
2306 if ( !control || ( extend &&
2307 listBox()->selectionMode() != QListBox::Extended &&
2308 listBox()->selectionMode() != QListBox::Multi ) )
2309 return FALSE;
2310
2311 QListBoxItem *item = listBox()->item( control -1 );
2312 if ( !item )
2313 return FALSE;
2314 if ( !extend ) {
2315 listBox()->setSelected( item, on );
2316 } else {
2317 int current = listBox()->currentItem();
2318 bool down = control > current;
2319 for ( int i = current; i != control;) {
2320 down ? i++ : i--;
2321 listBox()->setSelected( i, on );
2322 }
2323
2324 }
2325 return TRUE;
2326}
2327
2328/*! \reimp */
2329void QAccessibleListBox::clearSelection()
2330{
2331 listBox()->clearSelection();
2332}
2333
2334/*! \reimp */
2335QMemArray<int> QAccessibleListBox::selection() const
2336{
2337 QMemArray<int> array;
2338 uint size = 0;
2339 const uint c = listBox()->count();
2340 array.resize( c );
2341 for ( uint i = 0; i < c; ++i ) {
2342 if ( listBox()->isSelected( i ) ) {
2343 ++size;
2344 array[ (int)size-1 ] = i+1;
2345 }
2346 }
2347 array.resize( size );
2348 return array;
2349}
2350
2351/*!
2352 \class QAccessibleListView qaccessiblewidget.h
2353 \brief The QAccessibleListView class implements the QAccessibleInterface for list views.
2354*/
2355
2356static QListViewItem *findLVItem( QListView* listView, int control )
2357{
2358 int id = 1;
2359 QListViewItemIterator it( listView );
2360 QListViewItem *item = it.current();
2361 while ( item && id < control ) {
2362 ++it;
2363 ++id;
2364 item = it.current();
2365 }
2366 return item;
2367}
2368
2369/*!
2370 Constructs a QAccessibleListView object for \a o.
2371*/
2372QAccessibleListView::QAccessibleListView( QObject *o )
2373 : QAccessibleScrollView( o, Outline )
2374{
2375}
2376
2377/*! Returns the list view. */
2378QListView *QAccessibleListView::listView() const
2379{
2380 Q_ASSERT(widget()->inherits("QListView"));
2381 return (QListView*)widget();
2382}
2383
2384/*! \reimp */
2385int QAccessibleListView::itemAt( int x, int y ) const
2386{
2387 QListViewItem *item = listView()->itemAt( QPoint( x, y ) );
2388 if ( !item )
2389 return 0;
2390
2391 QListViewItemIterator it( listView() );
2392 int c = 1;
2393 while ( it.current() ) {
2394 if ( it.current() == item )
2395 return c;
2396 ++c;
2397 ++it;
2398 }
2399 return 0;
2400}
2401
2402/*! \reimp */
2403QRect QAccessibleListView::itemRect( int control ) const
2404{
2405 QListViewItem *item = findLVItem( listView(), control );
2406 if ( !item )
2407 return QRect();
2408 return listView()->itemRect( item );
2409}
2410
2411/*! \reimp */
2412int QAccessibleListView::itemCount() const
2413{
2414 QListViewItemIterator it( listView() );
2415 int c = 0;
2416 while ( it.current() ) {
2417 ++c;
2418 ++it;
2419 }
2420
2421 return c;
2422}
2423
2424/*! \reimp */
2425QString QAccessibleListView::text( Text t, int control ) const
2426{
2427 if ( !control || t != Name )
2428 return QAccessibleScrollView::text( t, control );
2429
2430 QListViewItem *item = findLVItem( listView(), control );
2431 if ( !item )
2432 return QString::null;
2433 return item->text( 0 );
2434}
2435
2436/*! \reimp */
2437QAccessible::Role QAccessibleListView::role( int control ) const
2438{
2439 if ( !control )
2440 return QAccessibleScrollView::role( control );
2441 return OutlineItem;
2442}
2443
2444/*! \reimp */
2445QAccessible::State QAccessibleListView::state( int control ) const
2446{
2447 int state = QAccessibleScrollView::state( control );
2448 QListViewItem *item;
2449 if ( !control || !( item = findLVItem( listView(), control ) ) )
2450 return (State)state;
2451
2452 if ( item->isSelectable() ) {
2453 if ( listView()->selectionMode() == QListView::Multi )
2454 state |= MultiSelectable;
2455 else if ( listView()->selectionMode() == QListView::Extended )
2456 state |= ExtSelectable;
2457 else if ( listView()->selectionMode() == QListView::Single )
2458 state |= Selectable;
2459 if ( item->isSelected() )
2460 state |= Selected;
2461 }
2462 if ( listView()->focusPolicy() != QWidget::NoFocus ) {
2463 state |= Focusable;
2464 if ( item == listView()->currentItem() )
2465 state |= Focused;
2466 }
2467 if ( item->childCount() ) {
2468 if ( item->isOpen() )
2469 state |= Expanded;
2470 else
2471 state |= Collapsed;
2472 }
2473 if ( !listView()->itemRect( item ).isValid() )
2474 state |= Invisible;
2475
2476 if ( item->rtti() == QCheckListItem::RTTI ) {
2477 if ( ((QCheckListItem*)item)->isOn() )
2478 state|=Checked;
2479 }
2480 return (State)state;
2481}
2482
2483/*! \reimp
2484QAccessibleInterface *QAccessibleListView::focusChild( int *control ) const
2485{
2486 QListViewItem *item = listView()->currentItem();
2487 if ( !item )
2488 return 0;
2489
2490 QListViewItemIterator it( listView() );
2491 int c = 1;
2492 while ( it.current() ) {
2493 if ( it.current() == item ) {
2494 *control = c;
2495 return (QAccessibleInterface*)this;
2496 }
2497 ++c;
2498 ++it;
2499 }
2500 return 0;
2501}
2502*/
2503/*! \reimp */
2504bool QAccessibleListView::setFocus( int control )
2505{
2506 bool res = QAccessibleScrollView::setFocus( 0 );
2507 if ( !control || !res )
2508 return res;
2509
2510 QListViewItem *item = findLVItem( listView(), control );
2511 if ( !item )
2512 return FALSE;
2513 listView()->setCurrentItem( item );
2514 return TRUE;
2515}
2516
2517/*! \reimp */
2518bool QAccessibleListView::setSelected( int control, bool on, bool extend )
2519{
2520 if ( !control || ( extend &&
2521 listView()->selectionMode() != QListView::Extended &&
2522 listView()->selectionMode() != QListView::Multi ) )
2523 return FALSE;
2524
2525 QListViewItem *item = findLVItem( listView(), control );
2526 if ( !item )
2527 return FALSE;
2528 if ( !extend ) {
2529 listView()->setSelected( item, on );
2530 } else {
2531 QListViewItem *current = listView()->currentItem();
2532 if ( !current )
2533 return FALSE;
2534 bool down = item->itemPos() > current->itemPos();
2535 QListViewItemIterator it( current );
2536 while ( it.current() ) {
2537 listView()->setSelected( it.current(), on );
2538 if ( it.current() == item )
2539 break;
2540 if ( down )
2541 ++it;
2542 else
2543 --it;
2544 }
2545 }
2546 return TRUE;
2547}
2548
2549/*! \reimp */
2550void QAccessibleListView::clearSelection()
2551{
2552 listView()->clearSelection();
2553}
2554
2555/*! \reimp */
2556QMemArray<int> QAccessibleListView::selection() const
2557{
2558 QMemArray<int> array;
2559 uint size = 0;
2560 int id = 1;
2561 array.resize( size );
2562 QListViewItemIterator it( listView() );
2563 while ( it.current() ) {
2564 if ( it.current()->isSelected() ) {
2565 ++size;
2566 array.resize( size );
2567 array[ (int)size-1 ] = id;
2568 }
2569 ++it;
2570 ++id;
2571 }
2572 return array;
2573}
2574
2575#ifndef QT_NO_ICONVIEW
2576/*!
2577 \class QAccessibleIconView qaccessiblewidget.h
2578 \brief The QAccessibleIconView class implements the QAccessibleInterface for icon views.
2579*/
2580
2581static QIconViewItem *findIVItem( QIconView *iconView, int control )
2582{
2583 int id = 1;
2584 QIconViewItem *item = iconView->firstItem();
2585 while ( item && id < control ) {
2586 item = item->nextItem();
2587 ++id;
2588 }
2589
2590 return item;
2591}
2592
2593/*!
2594 Constructs a QAccessibleIconView object for \a o.
2595*/
2596QAccessibleIconView::QAccessibleIconView( QObject *o )
2597 : QAccessibleScrollView( o, Outline )
2598{
2599 Q_ASSERT(widget()->inherits("QIconView"));
2600}
2601
2602/*! Returns the icon view. */
2603QIconView *QAccessibleIconView::iconView() const
2604{
2605 return (QIconView*)widget();
2606}
2607
2608/*! \reimp */
2609int QAccessibleIconView::itemAt( int x, int y ) const
2610{
2611 QIconViewItem *item = iconView()->findItem( QPoint( x, y ) );
2612 return iconView()->index( item ) + 1;
2613}
2614
2615/*! \reimp */
2616QRect QAccessibleIconView::itemRect( int control ) const
2617{
2618 QIconViewItem *item = findIVItem( iconView(), control );
2619
2620 if ( !item )
2621 return QRect();
2622 return item->rect();
2623}
2624
2625/*! \reimp */
2626int QAccessibleIconView::itemCount() const
2627{
2628 return iconView()->count();
2629}
2630
2631/*! \reimp */
2632QString QAccessibleIconView::text( Text t, int control ) const
2633{
2634 if ( !control || t != Name )
2635 return QAccessibleScrollView::text( t, control );
2636
2637 QIconViewItem *item = findIVItem( iconView(), control );
2638 if ( !item )
2639 return QString::null;
2640 return item->text();
2641}
2642
2643/*! \reimp */
2644QAccessible::Role QAccessibleIconView::role( int control ) const
2645{
2646 if ( !control )
2647 return QAccessibleScrollView::role( control );
2648 return OutlineItem;
2649}
2650
2651/*! \reimp */
2652QAccessible::State QAccessibleIconView::state( int control ) const
2653{
2654 int state = QAccessibleScrollView::state( control );
2655 QIconViewItem *item;
2656 if ( !control || !( item = findIVItem( iconView(), control ) ) )
2657 return (State)state;
2658
2659 if ( item->isSelectable() ) {
2660 if ( iconView()->selectionMode() == QIconView::Multi )
2661 state |= MultiSelectable;
2662 else if ( iconView()->selectionMode() == QIconView::Extended )
2663 state |= ExtSelectable;
2664 else if ( iconView()->selectionMode() == QIconView::Single )
2665 state |= Selectable;
2666 if ( item->isSelected() )
2667 state |= Selected;
2668 }
2669 if ( iconView()->itemsMovable() )
2670 state |= Moveable;
2671 if ( iconView()->focusPolicy() != QWidget::NoFocus ) {
2672 state |= Focusable;
2673 if ( item == iconView()->currentItem() )
2674 state |= Focused;
2675 }
2676
2677 return (State)state;
2678}
2679
2680/*! \reimp
2681QAccessibleInterface *QAccessibleIconView::focusChild( int *control ) const
2682{
2683 QIconViewItem *item = iconView()->currentItem();
2684 if ( !item )
2685 return 0;
2686
2687 *control = iconView()->index( item );
2688 return (QAccessibleInterface*)this;
2689}
2690*/
2691/*! \reimp */
2692bool QAccessibleIconView::setFocus( int control )
2693{
2694 bool res = QAccessibleScrollView::setFocus( 0 );
2695 if ( !control || !res )
2696 return res;
2697
2698 QIconViewItem *item = findIVItem( iconView(), control );
2699 if ( !item )
2700 return FALSE;
2701 iconView()->setCurrentItem( item );
2702 return TRUE;
2703}
2704
2705/*! \reimp */
2706bool QAccessibleIconView::setSelected( int control, bool on, bool extend )
2707{
2708 if ( !control || ( extend &&
2709 iconView()->selectionMode() != QIconView::Extended &&
2710 iconView()->selectionMode() != QIconView::Multi ) )
2711 return FALSE;
2712
2713 QIconViewItem *item = findIVItem( iconView(), control );
2714 if ( !item )
2715 return FALSE;
2716 if ( !extend ) {
2717 iconView()->setSelected( item, on, TRUE );
2718 } else {
2719 QIconViewItem *current = iconView()->currentItem();
2720 if ( !current )
2721 return FALSE;
2722 bool down = FALSE;
2723 QIconViewItem *temp = current;
2724 while ( ( temp = temp->nextItem() ) ) {
2725 if ( temp == item ) {
2726 down = TRUE;
2727 break;
2728 }
2729 }
2730 temp = current;
2731 if ( down ) {
2732 while ( ( temp = temp->nextItem() ) ) {
2733 iconView()->setSelected( temp, on, TRUE );
2734 if ( temp == item )
2735 break;
2736 }
2737 } else {
2738 while ( ( temp = temp->prevItem() ) ) {
2739 iconView()->setSelected( temp, on, TRUE );
2740 if ( temp == item )
2741 break;
2742 }
2743 }
2744 }
2745 return TRUE;
2746}
2747
2748/*! \reimp */
2749void QAccessibleIconView::clearSelection()
2750{
2751 iconView()->clearSelection();
2752}
2753
2754/*! \reimp */
2755QMemArray<int> QAccessibleIconView::selection() const
2756{
2757 QMemArray<int> array;
2758 uint size = 0;
2759 int id = 1;
2760 array.resize( iconView()->count() );
2761 QIconViewItem *item = iconView()->firstItem();
2762 while ( item ) {
2763 if ( item->isSelected() ) {
2764 ++size;
2765 array[ (int)size-1 ] = id;
2766 }
2767 item = item->nextItem();
2768 ++id;
2769 }
2770 array.resize( size );
2771 return array;
2772}
2773#endif
2774
2775
2776/*!
2777 \class QAccessibleTextEdit qaccessiblewidget.h
2778 \brief The QAccessibleTextEdit class implements the QAccessibleInterface for richtext editors.
2779*/
2780
2781/*!
2782 Constructs a QAccessibleTextEdit object for \a o.
2783*/
2784QAccessibleTextEdit::QAccessibleTextEdit( QObject *o )
2785: QAccessibleScrollView( o, Pane )
2786{
2787 Q_ASSERT(widget()->inherits("QTextEdit"));
2788}
2789
2790/*! Returns the text edit. */
2791QTextEdit *QAccessibleTextEdit::textEdit() const
2792{
2793
2794 return (QTextEdit*)widget();
2795}
2796
2797/*! \reimp */
2798int QAccessibleTextEdit::itemAt( int x, int y ) const
2799{
2800 int p;
2801 QPoint cp = textEdit()->viewportToContents( QPoint( x,y ) );
2802 textEdit()->charAt( cp , &p );
2803 return p + 1;
2804}
2805
2806/*! \reimp */
2807QRect QAccessibleTextEdit::itemRect( int item ) const
2808{
2809 QRect rect = textEdit()->paragraphRect( item - 1 );
2810 if ( !rect.isValid() )
2811 return QRect();
2812 QPoint ntl = textEdit()->contentsToViewport( QPoint( rect.x(), rect.y() ) );
2813 return QRect( ntl.x(), ntl.y(), rect.width(), rect.height() );
2814}
2815
2816/*! \reimp */
2817int QAccessibleTextEdit::itemCount() const
2818{
2819 return textEdit()->paragraphs();
2820}
2821
2822/*! \reimp */
2823QString QAccessibleTextEdit::text( Text t, int control ) const
2824{
2825 if (t == Name) {
2826 if (control)
2827 return textEdit()->text(control - 1);
2828 else
2829 return stripAmp(buddyString(widget()));
2830 } else if (t == Value) {
2831 if (control)
2832 return textEdit()->text(control - 1);
2833 else
2834 return textEdit()->text();
2835 }
2836
2837 return QAccessibleScrollView::text( t, control );
2838}
2839
2840/*! \reimp */
2841void QAccessibleTextEdit::setText(Text t, int control, const QString &text)
2842{
2843 if (control || t != Value) {
2844 QAccessibleScrollView::setText(t, control, text);
2845 return;
2846 }
2847 textEdit()->setText(text);
2848}
2849
2850/*! \reimp */
2851QAccessible::Role QAccessibleTextEdit::role( int control ) const
2852{
2853 if ( control )
2854 return EditableText;
2855 return QAccessibleScrollView::role( control );
2856}
Note: See TracBrowser for help on using the repository browser.