qaccessible.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
00004 ** All rights reserved.
00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
00006 **
00007 ** This file is part of the QtGui module of the Qt Toolkit.
00008 **
00009 ** $QT_BEGIN_LICENSE:LGPL$
00010 ** Commercial Usage
00011 ** Licensees holding valid Qt Commercial licenses may use this file in
00012 ** accordance with the Qt Commercial License Agreement provided with the
00013 ** Software or, alternatively, in accordance with the terms contained in
00014 ** a written agreement between you and Nokia.
00015 **
00016 ** GNU Lesser General Public License Usage
00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
00018 ** General Public License version 2.1 as published by the Free Software
00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
00020 ** packaging of this file.  Please review the following information to
00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
00023 **
00024 ** In addition, as a special exception, Nokia gives you certain additional
00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
00027 **
00028 ** GNU General Public License Usage
00029 ** Alternatively, this file may be used under the terms of the GNU
00030 ** General Public License version 3.0 as published by the Free Software
00031 ** Foundation and appearing in the file LICENSE.GPL included in the
00032 ** packaging of this file.  Please review the following information to
00033 ** ensure the GNU General Public License version 3.0 requirements will be
00034 ** met: http://www.gnu.org/copyleft/gpl.html.
00035 **
00036 ** If you have questions regarding the use of this file, please contact
00037 ** Nokia at qt-info@nokia.com.
00038 ** $QT_END_LICENSE$
00039 **
00040 ****************************************************************************/
00041 
00042 #ifndef QACCESSIBLE_H
00043 #define QACCESSIBLE_H
00044 
00045 #include <QtCore/qglobal.h>
00046 #include <QtCore/qobject.h>
00047 #include <QtCore/qrect.h>
00048 #include <QtCore/qset.h>
00049 #include <QtCore/qvector.h>
00050 #include <QtCore/qvariant.h>
00051 #include <QtGui/qcolor.h>
00052 #include <QtGui/qevent.h>
00053 
00054 QT_BEGIN_HEADER
00055 
00056 QT_BEGIN_NAMESPACE
00057 
00058 QT_MODULE(Gui)
00059 
00060 #ifndef QT_NO_ACCESSIBILITY
00061 
00062 class QAccessibleInterface;
00063 
00064 class Q_GUI_EXPORT QAccessible
00065 {
00066 public:
00067     enum Event {
00068         SoundPlayed          = 0x0001,
00069         Alert                = 0x0002,
00070         ForegroundChanged    = 0x0003,
00071         MenuStart            = 0x0004,
00072         MenuEnd              = 0x0005,
00073         PopupMenuStart       = 0x0006,
00074         PopupMenuEnd         = 0x0007,
00075         ContextHelpStart     = 0x000C,
00076         ContextHelpEnd       = 0x000D,
00077         DragDropStart        = 0x000E,
00078         DragDropEnd          = 0x000F,
00079         DialogStart          = 0x0010,
00080         DialogEnd            = 0x0011,
00081         ScrollingStart       = 0x0012,
00082         ScrollingEnd         = 0x0013,
00083 
00084         MenuCommand          = 0x0018,
00085 
00086         ObjectCreated        = 0x8000,
00087         ObjectDestroyed      = 0x8001,
00088         ObjectShow           = 0x8002,
00089         ObjectHide           = 0x8003,
00090         ObjectReorder        = 0x8004,
00091         Focus                = 0x8005,
00092         Selection            = 0x8006,
00093         SelectionAdd         = 0x8007,
00094         SelectionRemove      = 0x8008,
00095         SelectionWithin      = 0x8009,
00096         StateChanged         = 0x800A,
00097         LocationChanged      = 0x800B,
00098         NameChanged          = 0x800C,
00099         DescriptionChanged   = 0x800D,
00100         ValueChanged         = 0x800E,
00101         ParentChanged        = 0x800F,
00102         HelpChanged          = 0x80A0,
00103         DefaultActionChanged = 0x80B0,
00104         AcceleratorChanged   = 0x80C0
00105     };
00106 
00107     enum StateFlag {
00108         Normal          = 0x00000000,
00109         Unavailable     = 0x00000001,
00110         Selected        = 0x00000002,
00111         Focused         = 0x00000004,
00112         Pressed         = 0x00000008,
00113         Checked         = 0x00000010,
00114         Mixed           = 0x00000020,
00115         ReadOnly        = 0x00000040,
00116         HotTracked      = 0x00000080,
00117         DefaultButton   = 0x00000100,
00118         Expanded        = 0x00000200,
00119         Collapsed       = 0x00000400,
00120         Busy            = 0x00000800,
00121         // Floating        = 0x00001000,
00122         Marqueed        = 0x00002000,
00123         Animated        = 0x00004000,
00124         Invisible       = 0x00008000,
00125         Offscreen       = 0x00010000,
00126         Sizeable        = 0x00020000,
00127         Movable         = 0x00040000,
00128 #ifdef QT3_SUPPORT
00129         Moveable        = Movable,
00130 #endif
00131         SelfVoicing     = 0x00080000,
00132         Focusable       = 0x00100000,
00133         Selectable      = 0x00200000,
00134         Linked          = 0x00400000,
00135         Traversed       = 0x00800000,
00136         MultiSelectable = 0x01000000,
00137         ExtSelectable   = 0x02000000,
00138         //AlertLow        = 0x04000000,
00139         //AlertMedium     = 0x08000000,
00140         //AlertHigh       = 0x10000000, /* reused for HasInvokeExtension */
00141         Protected       = 0x20000000,
00142         HasPopup        = 0x40000000,
00143         Modal           = 0x80000000,
00144 
00145         HasInvokeExtension = 0x10000000 // internal
00146     };
00147     Q_DECLARE_FLAGS(State, StateFlag)
00148 
00149     enum Role {
00150         NoRole         = 0x00000000,
00151         TitleBar       = 0x00000001,
00152         MenuBar        = 0x00000002,
00153         ScrollBar      = 0x00000003,
00154         Grip           = 0x00000004,
00155         Sound          = 0x00000005,
00156         Cursor         = 0x00000006,
00157         Caret          = 0x00000007,
00158         AlertMessage   = 0x00000008,
00159         Window         = 0x00000009,
00160         Client         = 0x0000000A,
00161         PopupMenu      = 0x0000000B,
00162         MenuItem       = 0x0000000C,
00163         ToolTip        = 0x0000000D,
00164         Application    = 0x0000000E,
00165         Document       = 0x0000000F,
00166         Pane           = 0x00000010,
00167         Chart          = 0x00000011,
00168         Dialog         = 0x00000012,
00169         Border         = 0x00000013,
00170         Grouping       = 0x00000014,
00171         Separator      = 0x00000015,
00172         ToolBar        = 0x00000016,
00173         StatusBar      = 0x00000017,
00174         Table          = 0x00000018,
00175         ColumnHeader   = 0x00000019,
00176         RowHeader      = 0x0000001A,
00177         Column         = 0x0000001B,
00178         Row            = 0x0000001C,
00179         Cell           = 0x0000001D,
00180         Link           = 0x0000001E,
00181         HelpBalloon    = 0x0000001F,
00182         Assistant      = 0x00000020,
00183         List           = 0x00000021,
00184         ListItem       = 0x00000022,
00185         Tree           = 0x00000023,
00186         TreeItem       = 0x00000024,
00187         PageTab        = 0x00000025,
00188         PropertyPage   = 0x00000026,
00189         Indicator      = 0x00000027,
00190         Graphic        = 0x00000028,
00191         StaticText     = 0x00000029,
00192         EditableText   = 0x0000002A,  // Editable, selectable, etc.
00193         PushButton     = 0x0000002B,
00194         CheckBox       = 0x0000002C,
00195         RadioButton    = 0x0000002D,
00196         ComboBox       = 0x0000002E,
00197         // DropList       = 0x0000002F,
00198         ProgressBar    = 0x00000030,
00199         Dial           = 0x00000031,
00200         HotkeyField    = 0x00000032,
00201         Slider         = 0x00000033,
00202         SpinBox        = 0x00000034,
00203         Canvas         = 0x00000035,
00204         Animation      = 0x00000036,
00205         Equation       = 0x00000037,
00206         ButtonDropDown = 0x00000038,
00207         ButtonMenu     = 0x00000039,
00208         ButtonDropGrid = 0x0000003A,
00209         Whitespace     = 0x0000003B,
00210         PageTabList    = 0x0000003C,
00211         Clock          = 0x0000003D,
00212         Splitter       = 0x0000003E,
00213         // Additional Qt roles where enum value does not map directly to MSAA:
00214         LayeredPane    = 0x0000003F,
00215         UserRole       = 0x0000ffff
00216     };
00217 
00218     enum Text {
00219         Name         = 0,
00220         Description,
00221         Value,
00222         Help,
00223         Accelerator,
00224         UserText     = 0x0000ffff
00225     };
00226 
00227     enum RelationFlag {
00228         Unrelated     = 0x00000000,
00229         Self          = 0x00000001,
00230         Ancestor      = 0x00000002,
00231         Child         = 0x00000004,
00232         Descendent    = 0x00000008,
00233         Sibling       = 0x00000010,
00234         HierarchyMask = 0x000000ff,
00235 
00236         Up            = 0x00000100,
00237         Down          = 0x00000200,
00238         Left          = 0x00000400,
00239         Right         = 0x00000800,
00240         Covers        = 0x00001000,
00241         Covered       = 0x00002000,
00242         GeometryMask  = 0x0000ff00,
00243 
00244         FocusChild    = 0x00010000,
00245         Label         = 0x00020000,
00246         Labelled      = 0x00040000,
00247         Controller    = 0x00080000,
00248         Controlled    = 0x00100000,
00249         LogicalMask   = 0x00ff0000
00250     };
00251     Q_DECLARE_FLAGS(Relation, RelationFlag)
00252 
00253     enum Action {
00254         DefaultAction       = 0,
00255         Press               = -1,
00256         FirstStandardAction = Press,
00257         SetFocus            = -2,
00258         Increase            = -3,
00259         Decrease            = -4,
00260         Accept              = -5,
00261         Cancel              = -6,
00262         Select              = -7,
00263         ClearSelection      = -8,
00264         RemoveSelection     = -9,
00265         ExtendSelection     = -10,
00266         AddToSelection      = -11,
00267         LastStandardAction  = AddToSelection
00268     };
00269 
00270     enum Method {
00271         ListSupportedMethods      = 0,
00272         SetCursorPosition         = 1,
00273         GetCursorPosition         = 2,
00274         ForegroundColor           = 3,
00275         BackgroundColor           = 4
00276     };
00277 
00278     typedef QAccessibleInterface*(*InterfaceFactory)(const QString &key, QObject*);
00279     typedef void(*UpdateHandler)(QObject*, int who, Event reason);
00280     typedef void(*RootObjectHandler)(QObject*);
00281 
00282     static void installFactory(InterfaceFactory);
00283     static void removeFactory(InterfaceFactory);
00284     static UpdateHandler installUpdateHandler(UpdateHandler);
00285     static RootObjectHandler installRootObjectHandler(RootObjectHandler);
00286 
00287     static QAccessibleInterface *queryAccessibleInterface(QObject *);
00288     static void updateAccessibility(QObject *, int who, Event reason);
00289     static bool isActive();
00290     static void setRootObject(QObject*);
00291 
00292     static void initialize();
00293     static void cleanup();
00294 
00295 private:
00296     static UpdateHandler updateHandler;
00297     static RootObjectHandler rootObjectHandler;
00298 };
00299 
00300 Q_DECLARE_OPERATORS_FOR_FLAGS(QAccessible::State)
00301 Q_DECLARE_OPERATORS_FOR_FLAGS(QAccessible::Relation)
00302 QT_END_NAMESPACE
00303 Q_DECLARE_METATYPE(QSet<QAccessible::Method>)
00304 QT_BEGIN_NAMESPACE
00305 
00306 namespace QAccessible2
00307 {
00308     enum InterfaceType
00309     {
00310         TextInterface,
00311         EditableTextInterface,
00312         ValueInterface,
00313         TableInterface,
00314         ActionInterface,
00315         ImageInterface
00316     };
00317 }
00318 
00319 class QAccessible2Interface;
00320 class QAccessibleTextInterface;
00321 class QAccessibleEditableTextInterface;
00322 class QAccessibleValueInterface;
00323 class QAccessibleTableInterface;
00324 class QAccessibleActionInterface;
00325 class QAccessibleImageInterface;
00326 
00327 class Q_GUI_EXPORT QAccessibleInterface : public QAccessible
00328 {
00329 public:
00330     virtual ~QAccessibleInterface() {}
00331     // check for valid pointers
00332     virtual bool isValid() const = 0;
00333     virtual QObject *object() const = 0;
00334 
00335     // hierarchy
00336     virtual int childCount() const = 0;
00337     virtual int indexOfChild(const QAccessibleInterface *) const = 0;
00338 
00339     // relations
00340     virtual Relation relationTo(int child, const QAccessibleInterface *other,
00341                                 int otherChild) const = 0;
00342     virtual int childAt(int x, int y) const = 0;
00343 
00344     // navigation
00345     virtual int navigate(RelationFlag relation, int index, QAccessibleInterface **iface) const = 0;
00346 
00347     // properties and state
00348     virtual QString text(Text t, int child) const = 0;
00349     virtual void setText(Text t, int child, const QString &text) = 0;
00350     virtual QRect rect(int child) const = 0;
00351     virtual Role role(int child) const = 0;
00352     virtual State state(int child) const = 0;
00353 
00354     // action
00355     virtual int userActionCount(int child) const = 0;
00356     virtual QString actionText(int action, Text t, int child) const = 0;
00357     virtual bool doAction(int action, int child, const QVariantList &params = QVariantList()) = 0;
00358 
00359     QVariant invokeMethod(Method method, int child = 0,
00360                           const QVariantList &params = QVariantList());
00361 
00362     inline QSet<Method> supportedMethods()
00363     { return qvariant_cast<QSet<Method> >(invokeMethod(ListSupportedMethods)); }
00364 
00365     inline QColor foregroundColor()
00366     { return qvariant_cast<QColor>(invokeMethod(ForegroundColor)); }
00367 
00368     inline QColor backgroundColor()
00369     { return qvariant_cast<QColor>(invokeMethod(BackgroundColor)); }
00370 
00371     inline QAccessibleTextInterface *textInterface()
00372     { return reinterpret_cast<QAccessibleTextInterface *>(cast_helper(QAccessible2::TextInterface)); }
00373 
00374     inline QAccessibleEditableTextInterface *editableTextInterface()
00375     { return reinterpret_cast<QAccessibleEditableTextInterface *>(cast_helper(QAccessible2::EditableTextInterface)); }
00376 
00377     inline QAccessibleValueInterface *valueInterface()
00378     { return reinterpret_cast<QAccessibleValueInterface *>(cast_helper(QAccessible2::ValueInterface)); }
00379 
00380     inline QAccessibleTableInterface *tableInterface()
00381     { return reinterpret_cast<QAccessibleTableInterface *>(cast_helper(QAccessible2::TableInterface)); }
00382 
00383     inline QAccessibleActionInterface *actionInterface()
00384     { return reinterpret_cast<QAccessibleActionInterface *>(cast_helper(QAccessible2::ActionInterface)); }
00385 
00386     inline QAccessibleImageInterface *imageInterface()
00387     { return reinterpret_cast<QAccessibleImageInterface *>(cast_helper(QAccessible2::ImageInterface)); }
00388 
00389 private:
00390     QAccessible2Interface *cast_helper(QAccessible2::InterfaceType);
00391 };
00392 
00393 class Q_GUI_EXPORT QAccessibleInterfaceEx: public QAccessibleInterface
00394 {
00395 public:
00396     virtual QVariant invokeMethodEx(Method method, int child, const QVariantList &params) = 0;
00397     virtual QVariant virtual_hook(const QVariant &data);
00398     virtual QAccessible2Interface *interface_cast(QAccessible2::InterfaceType)
00399     { return 0; }
00400 };
00401 
00402 
00403 class Q_GUI_EXPORT QAccessibleEvent : public QEvent
00404 {
00405 public:
00406     inline QAccessibleEvent(Type type, int child);
00407     inline int child() const { return c; }
00408     inline QString value() const { return val; }
00409     inline void setValue(const QString &aText) { val = aText; }
00410 
00411 private:
00412     int c;
00413     QString val;
00414 };
00415 
00416 inline QAccessibleEvent::QAccessibleEvent(Type atype, int achild)
00417     : QEvent(atype), c(achild) {}
00418 
00419 #define QAccessibleInterface_iid "com.trolltech.Qt.QAccessibleInterface"
00420 Q_DECLARE_INTERFACE(QAccessibleInterface, QAccessibleInterface_iid)
00421 
00422 #endif // QT_NO_ACCESSIBILITY
00423 
00424 QT_END_NAMESPACE
00425 
00426 QT_END_HEADER
00427 
00428 #endif // QACCESSIBLE_H