qaccessible.h
上传用户:detong
上传日期:2022-06-22
资源大小:20675k
文件大小:14k
源码类别:

系统编程

开发平台:

Unix_Linux

  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
  4. ** Contact: Qt Software Information (qt-info@nokia.com)
  5. **
  6. ** This file is part of the QtGui module of the Qt Toolkit.
  7. **
  8. ** Commercial Usage
  9. ** Licensees holding valid Qt Commercial licenses may use this file in
  10. ** accordance with the Qt Commercial License Agreement provided with the
  11. ** Software or, alternatively, in accordance with the terms contained in
  12. ** a written agreement between you and Nokia.
  13. **
  14. **
  15. ** GNU General Public License Usage
  16. ** Alternatively, this file may be used under the terms of the GNU
  17. ** General Public License versions 2.0 or 3.0 as published by the Free
  18. ** Software Foundation and appearing in the file LICENSE.GPL included in
  19. ** the packaging of this file.  Please review the following information
  20. ** to ensure GNU General Public Licensing requirements will be met:
  21. ** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
  22. ** http://www.gnu.org/copyleft/gpl.html.  In addition, as a special
  23. ** exception, Nokia gives you certain additional rights. These rights
  24. ** are described in the Nokia Qt GPL Exception version 1.3, included in
  25. ** the file GPL_EXCEPTION.txt in this package.
  26. **
  27. ** Qt for Windows(R) Licensees
  28. ** As a special exception, Nokia, as the sole copyright holder for Qt
  29. ** Designer, grants users of the Qt/Eclipse Integration plug-in the
  30. ** right for the Qt/Eclipse Integration to link to functionality
  31. ** provided by Qt Designer and its related libraries.
  32. **
  33. ** If you are unsure which license is appropriate for your use, please
  34. ** contact the sales department at qt-sales@nokia.com.
  35. **
  36. ****************************************************************************/
  37. #ifndef QACCESSIBLE_H
  38. #define QACCESSIBLE_H
  39. #include <QtCore/qglobal.h>
  40. #include <QtCore/qobject.h>
  41. #include <QtCore/qrect.h>
  42. #include <QtCore/qset.h>
  43. #include <QtCore/qvector.h>
  44. #include <QtCore/qvariant.h>
  45. #include <QtGui/qcolor.h>
  46. #include <QtGui/qevent.h>
  47. QT_BEGIN_HEADER
  48. QT_BEGIN_NAMESPACE
  49. QT_MODULE(Gui)
  50. #ifndef QT_NO_ACCESSIBILITY
  51. class QAccessibleInterface;
  52. class Q_GUI_EXPORT QAccessible
  53. {
  54. public:
  55.     enum Event {
  56.         SoundPlayed          = 0x0001,
  57.         Alert                = 0x0002,
  58.         ForegroundChanged    = 0x0003,
  59.         MenuStart            = 0x0004,
  60.         MenuEnd              = 0x0005,
  61.         PopupMenuStart       = 0x0006,
  62.         PopupMenuEnd         = 0x0007,
  63.         ContextHelpStart     = 0x000C,
  64.         ContextHelpEnd       = 0x000D,
  65.         DragDropStart        = 0x000E,
  66.         DragDropEnd          = 0x000F,
  67.         DialogStart          = 0x0010,
  68.         DialogEnd            = 0x0011,
  69.         ScrollingStart       = 0x0012,
  70.         ScrollingEnd         = 0x0013,
  71.         MenuCommand          = 0x0018,
  72.         ObjectCreated        = 0x8000,
  73.         ObjectDestroyed      = 0x8001,
  74.         ObjectShow           = 0x8002,
  75.         ObjectHide           = 0x8003,
  76.         ObjectReorder        = 0x8004,
  77.         Focus                = 0x8005,
  78.         Selection            = 0x8006,
  79.         SelectionAdd         = 0x8007,
  80.         SelectionRemove      = 0x8008,
  81.         SelectionWithin      = 0x8009,
  82.         StateChanged         = 0x800A,
  83.         LocationChanged      = 0x800B,
  84.         NameChanged          = 0x800C,
  85.         DescriptionChanged   = 0x800D,
  86.         ValueChanged         = 0x800E,
  87.         ParentChanged        = 0x800F,
  88.         HelpChanged          = 0x80A0,
  89.         DefaultActionChanged = 0x80B0,
  90.         AcceleratorChanged   = 0x80C0
  91.     };
  92.     enum StateFlag {
  93.         Normal          = 0x00000000,
  94.         Unavailable     = 0x00000001,
  95.         Selected        = 0x00000002,
  96.         Focused         = 0x00000004,
  97.         Pressed         = 0x00000008,
  98.         Checked         = 0x00000010,
  99.         Mixed           = 0x00000020,
  100.         ReadOnly        = 0x00000040,
  101.         HotTracked      = 0x00000080,
  102.         DefaultButton   = 0x00000100,
  103.         Expanded        = 0x00000200,
  104.         Collapsed       = 0x00000400,
  105.         Busy            = 0x00000800,
  106.         // Floating        = 0x00001000,
  107.         Marqueed        = 0x00002000,
  108.         Animated        = 0x00004000,
  109.         Invisible       = 0x00008000,
  110.         Offscreen       = 0x00010000,
  111.         Sizeable        = 0x00020000,
  112.         Movable         = 0x00040000,
  113. #ifdef QT3_SUPPORT
  114.         Moveable        = Movable,
  115. #endif
  116.         SelfVoicing     = 0x00080000,
  117.         Focusable       = 0x00100000,
  118.         Selectable      = 0x00200000,
  119.         Linked          = 0x00400000,
  120.         Traversed       = 0x00800000,
  121.         MultiSelectable = 0x01000000,
  122.         ExtSelectable   = 0x02000000,
  123.         //AlertLow        = 0x04000000,
  124.         //AlertMedium     = 0x08000000,
  125.         //AlertHigh       = 0x10000000, /* reused for HasInvokeExtension */
  126.         Protected       = 0x20000000,
  127.         HasPopup        = 0x40000000,
  128.         Modal           = 0x80000000,
  129.         HasInvokeExtension = 0x10000000 // internal
  130.     };
  131.     Q_DECLARE_FLAGS(State, StateFlag)
  132.     enum Role {
  133.         NoRole         = 0x00000000,
  134.         TitleBar       = 0x00000001,
  135.         MenuBar        = 0x00000002,
  136.         ScrollBar      = 0x00000003,
  137.         Grip           = 0x00000004,
  138.         Sound          = 0x00000005,
  139.         Cursor         = 0x00000006,
  140.         Caret          = 0x00000007,
  141.         AlertMessage   = 0x00000008,
  142.         Window         = 0x00000009,
  143.         Client         = 0x0000000A,
  144.         PopupMenu      = 0x0000000B,
  145.         MenuItem       = 0x0000000C,
  146.         ToolTip        = 0x0000000D,
  147.         Application    = 0x0000000E,
  148.         Document       = 0x0000000F,
  149.         Pane           = 0x00000010,
  150.         Chart          = 0x00000011,
  151.         Dialog         = 0x00000012,
  152.         Border         = 0x00000013,
  153.         Grouping       = 0x00000014,
  154.         Separator      = 0x00000015,
  155.         ToolBar        = 0x00000016,
  156.         StatusBar      = 0x00000017,
  157.         Table          = 0x00000018,
  158.         ColumnHeader   = 0x00000019,
  159.         RowHeader      = 0x0000001A,
  160.         Column         = 0x0000001B,
  161.         Row            = 0x0000001C,
  162.         Cell           = 0x0000001D,
  163.         Link           = 0x0000001E,
  164.         HelpBalloon    = 0x0000001F,
  165.         Assistant      = 0x00000020,
  166.         List           = 0x00000021,
  167.         ListItem       = 0x00000022,
  168.         Tree           = 0x00000023,
  169.         TreeItem       = 0x00000024,
  170.         PageTab        = 0x00000025,
  171.         PropertyPage   = 0x00000026,
  172.         Indicator      = 0x00000027,
  173.         Graphic        = 0x00000028,
  174.         StaticText     = 0x00000029,
  175.         EditableText   = 0x0000002A,  // Editable, selectable, etc.
  176.         PushButton     = 0x0000002B,
  177.         CheckBox       = 0x0000002C,
  178.         RadioButton    = 0x0000002D,
  179.         ComboBox       = 0x0000002E,
  180.         // DropList       = 0x0000002F,
  181.         ProgressBar    = 0x00000030,
  182.         Dial           = 0x00000031,
  183.         HotkeyField    = 0x00000032,
  184.         Slider         = 0x00000033,
  185.         SpinBox        = 0x00000034,
  186.         Canvas         = 0x00000035,
  187.         Animation      = 0x00000036,
  188.         Equation       = 0x00000037,
  189.         ButtonDropDown = 0x00000038,
  190.         ButtonMenu     = 0x00000039,
  191.         ButtonDropGrid = 0x0000003A,
  192.         Whitespace     = 0x0000003B,
  193.         PageTabList    = 0x0000003C,
  194.         Clock          = 0x0000003D,
  195.         Splitter       = 0x0000003E,
  196.         LayeredPane    = 0x0000003F,
  197.         UserRole       = 0x0000ffff
  198.     };
  199.     enum Text {
  200.         Name         = 0,
  201.         Description,
  202.         Value,
  203.         Help,
  204.         Accelerator,
  205.         UserText     = 0x0000ffff
  206.     };
  207.     enum RelationFlag {
  208.         Unrelated     = 0x00000000,
  209.         Self          = 0x00000001,
  210.         Ancestor      = 0x00000002,
  211.         Child         = 0x00000004,
  212.         Descendent    = 0x00000008,
  213.         Sibling       = 0x00000010,
  214.         HierarchyMask = 0x000000ff,
  215.         Up            = 0x00000100,
  216.         Down          = 0x00000200,
  217.         Left          = 0x00000400,
  218.         Right         = 0x00000800,
  219.         Covers        = 0x00001000,
  220.         Covered       = 0x00002000,
  221.         GeometryMask  = 0x0000ff00,
  222.         FocusChild    = 0x00010000,
  223.         Label         = 0x00020000,
  224.         Labelled      = 0x00040000,
  225.         Controller    = 0x00080000,
  226.         Controlled    = 0x00100000,
  227.         LogicalMask   = 0x00ff0000
  228.     };
  229.     Q_DECLARE_FLAGS(Relation, RelationFlag)
  230.     enum Action {
  231.         DefaultAction       = 0,
  232.         Press               = -1,
  233.         FirstStandardAction = Press,
  234.         SetFocus            = -2,
  235.         Increase            = -3,
  236.         Decrease            = -4,
  237.         Accept              = -5,
  238.         Cancel             = -6,
  239.         Select              = -7,
  240.         ClearSelection      = -8,
  241.         RemoveSelection     = -9,
  242.         ExtendSelection     = -10,
  243.         AddToSelection      = -11,
  244.         LastStandardAction  = AddToSelection
  245.     };
  246.     enum Method {
  247.         ListSupportedMethods      = 0,
  248.         SetCursorPosition         = 1,
  249.         GetCursorPosition         = 2,
  250.         ForegroundColor           = 3,
  251.         BackgroundColor           = 4
  252.     };
  253.     typedef QAccessibleInterface*(*InterfaceFactory)(const QString &key, QObject*);
  254.     typedef void(*UpdateHandler)(QObject*, int who, Event reason);
  255.     typedef void(*RootObjectHandler)(QObject*);
  256.     static void installFactory(InterfaceFactory);
  257.     static void removeFactory(InterfaceFactory);
  258.     static UpdateHandler installUpdateHandler(UpdateHandler);
  259.     static RootObjectHandler installRootObjectHandler(RootObjectHandler);
  260.     static QAccessibleInterface *queryAccessibleInterface(QObject *);
  261.     static void updateAccessibility(QObject *, int who, Event reason);
  262.     static bool isActive();
  263.     static void setRootObject(QObject*);
  264.     static void initialize();
  265.     static void cleanup();
  266. private:
  267.     static UpdateHandler updateHandler;
  268.     static RootObjectHandler rootObjectHandler;
  269. };
  270. Q_DECLARE_OPERATORS_FOR_FLAGS(QAccessible::State)
  271. Q_DECLARE_OPERATORS_FOR_FLAGS(QAccessible::Relation)
  272. QT_END_NAMESPACE
  273. Q_DECLARE_METATYPE(QSet<QAccessible::Method>)
  274. QT_BEGIN_NAMESPACE
  275. namespace QAccessible2
  276. {
  277.     enum InterfaceType
  278.     {
  279.         TextInterface,
  280.         EditableTextInterface,
  281.         ValueInterface,
  282.         TableInterface
  283.     };
  284. }
  285. class QAccessible2Interface;
  286. class QAccessibleTextInterface;
  287. class QAccessibleEditableTextInterface;
  288. class QAccessibleValueInterface;
  289. class QAccessibleTableInterface;
  290. class Q_GUI_EXPORT QAccessibleInterface : public QAccessible
  291. {
  292. public:
  293.     virtual ~QAccessibleInterface() {}
  294.     // check for valid pointers
  295.     virtual bool isValid() const = 0;
  296.     virtual QObject *object() const = 0;
  297.     // hierarchy
  298.     virtual int childCount() const = 0;
  299.     virtual int indexOfChild(const QAccessibleInterface *) const = 0;
  300.     // relations
  301.     virtual Relation relationTo(int child, const QAccessibleInterface *other,
  302.                                 int otherChild) const = 0;
  303.     virtual int childAt(int x, int y) const = 0;
  304.     // navigation
  305.     virtual int navigate(RelationFlag relation, int index, QAccessibleInterface **iface) const = 0;
  306.     // properties and state
  307.     virtual QString text(Text t, int child) const = 0;
  308.     virtual void setText(Text t, int child, const QString &text) = 0;
  309.     virtual QRect rect(int child) const = 0;
  310.     virtual Role role(int child) const = 0;
  311.     virtual State state(int child) const = 0;
  312.     // action
  313.     virtual int userActionCount(int child) const = 0;
  314.     virtual QString actionText(int action, Text t, int child) const = 0;
  315.     virtual bool doAction(int action, int child, const QVariantList &params = QVariantList()) = 0;
  316.     QVariant invokeMethod(Method method, int child = 0,
  317.                           const QVariantList &params = QVariantList());
  318.     inline QSet<Method> supportedMethods()
  319.     { return qvariant_cast<QSet<Method> >(invokeMethod(ListSupportedMethods)); }
  320.     inline QColor foregroundColor()
  321.     { return qvariant_cast<QColor>(invokeMethod(ForegroundColor)); }
  322.     inline QColor backgroundColor()
  323.     { return qvariant_cast<QColor>(invokeMethod(BackgroundColor)); }
  324.     inline QAccessibleTextInterface *textInterface()
  325.     { return reinterpret_cast<QAccessibleTextInterface *>(cast_helper(QAccessible2::TextInterface)); }
  326.     inline QAccessibleEditableTextInterface *editableTextInterface()
  327.     { return reinterpret_cast<QAccessibleEditableTextInterface *>(cast_helper(QAccessible2::EditableTextInterface)); }
  328.     inline QAccessibleValueInterface *valueInterface()
  329.     { return reinterpret_cast<QAccessibleValueInterface *>(cast_helper(QAccessible2::ValueInterface)); }
  330.     inline QAccessibleTableInterface *tableInterface()
  331.     { return reinterpret_cast<QAccessibleTableInterface *>(cast_helper(QAccessible2::TableInterface)); }
  332. private:
  333.     QAccessible2Interface *cast_helper(QAccessible2::InterfaceType);
  334. };
  335. class Q_GUI_EXPORT QAccessibleInterfaceEx: public QAccessibleInterface
  336. {
  337. public:
  338.     virtual QVariant invokeMethodEx(Method method, int child, const QVariantList &params) = 0;
  339.     virtual QVariant virtual_hook(const QVariant &data);
  340.     virtual QAccessible2Interface *interface_cast(QAccessible2::InterfaceType)
  341.     { return 0; }
  342. };
  343. class Q_GUI_EXPORT QAccessibleEvent : public QEvent
  344. {
  345. public:
  346.     inline QAccessibleEvent(Type type, int child);
  347.     inline int child() const { return c; }
  348.     inline QString value() const { return val; }
  349.     inline void setValue(const QString &aText) { val = aText; }
  350. private:
  351.     int c;
  352.     QString val;
  353. };
  354. inline QAccessibleEvent::QAccessibleEvent(Type atype, int achild)
  355.     : QEvent(atype), c(achild) {}
  356. #define QAccessibleInterface_iid "com.trolltech.Qt.QAccessibleInterface"
  357. Q_DECLARE_INTERFACE(QAccessibleInterface, QAccessibleInterface_iid)
  358. #endif // QT_NO_ACCESSIBILITY
  359. QT_END_NAMESPACE
  360. QT_END_HEADER
  361. #endif // QACCESSIBLE_H