Add implementations of QAIM::sibling in public APIs.
[profile/ivi/qtbase.git] / src / gui / accessible / qaccessible.h
index e57033d..1fb6c65 100644 (file)
@@ -1,38 +1,38 @@
 /****************************************************************************
 **
-** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
 **
 ** This file is part of the QtGui module of the Qt Toolkit.
 **
 ** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.  For licensing terms and
+** conditions see http://qt.digia.com/licensing.  For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
 ** GNU Lesser General Public License Usage
-** This file may be used under the terms of the GNU Lesser General Public
-** License version 2.1 as published by the Free Software Foundation and
-** appearing in the file LICENSE.LGPL included in the packaging of this
-** file. Please review the following information to ensure the GNU Lesser
-** General Public License version 2.1 requirements will be met:
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 **
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
+** In addition, as a special exception, Digia gives you certain additional
+** rights.  These rights are described in the Digia Qt LGPL Exception
 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 **
 ** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU General
-** Public License version 3.0 as published by the Free Software Foundation
-** and appearing in the file LICENSE.GPL included in the packaging of this
-** file. Please review the following information to ensure the GNU General
-** Public License version 3.0 requirements will be met:
-** http://www.gnu.org/copyleft/gpl.html.
-**
-** Other Usage
-** Alternatively, this file may be used in accordance with the terms and
-** conditions contained in a signed written agreement between you and Nokia.
-**
-**
-**
-**
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
 **
 **
 ** $QT_END_LICENSE$
 #include <QtGui/qcolor.h>
 #include <QtGui/qevent.h>
 
+#include <stdlib.h>
+
 QT_BEGIN_HEADER
 
 QT_BEGIN_NAMESPACE
 
 
-#ifndef QT_NO_ACCESSIBILITY
-
 class QAccessibleInterface;
 class QAccessibleEvent;
 class QWindow;
@@ -145,7 +145,9 @@ public:
         ParentChanged        = 0x800F,
         HelpChanged          = 0x80A0,
         DefaultActionChanged = 0x80B0,
-        AcceleratorChanged   = 0x80C0
+        AcceleratorChanged   = 0x80C0,
+
+        InvalidEvent
     };
 
     // 64 bit enums seem hard on some platforms (windows...)
@@ -214,7 +216,7 @@ public:
         // quint64 alertHigh : 1;
 
         State() {
-            qMemSet(this, 0, sizeof(State));
+            memset(this, 0, sizeof(State));
         }
     };
 
@@ -289,9 +291,12 @@ public:
         PageTabList    = 0x0000003C,
         Clock          = 0x0000003D,
         Splitter       = 0x0000003E,
+        // Reserved space in case MSAA roles needs to be added
+
         // Additional Qt roles where enum value does not map directly to MSAA:
-        LayeredPane    = 0x0000003F,
-        Terminal       = 0x00000040,
+        LayeredPane    = 0x00000080,
+        Terminal       = 0x00000081,
+        Desktop        = 0x00000082,
         UserRole       = 0x0000ffff
     };
 
@@ -306,10 +311,10 @@ public:
     };
 
     enum RelationFlag {
-        Label         = 0x00020000,
-        Labelled      = 0x00040000,
-        Controller    = 0x00080000,
-        Controlled    = 0x00100000,
+        Label         = 0x00000001,
+        Labelled      = 0x00000002,
+        Controller    = 0x00000004,
+        Controlled    = 0x00000008,
         AllRelations  = 0xffffffff
     };
     Q_DECLARE_FLAGS(Relation, RelationFlag)
@@ -326,7 +331,7 @@ public:
     };
 
     typedef QAccessibleInterface*(*InterfaceFactory)(const QString &key, QObject*);
-    typedef void(*UpdateHandler)(const QAccessibleEvent &event);
+    typedef void(*UpdateHandler)(QAccessibleEvent *event);
     typedef void(*RootObjectHandler)(QObject*);
 
     static void installFactory(InterfaceFactory);
@@ -335,9 +340,10 @@ public:
     static RootObjectHandler installRootObjectHandler(RootObjectHandler);
 
     static QAccessibleInterface *queryAccessibleInterface(QObject *);
-
-    static void updateAccessibility(QObject *object, int child, Event reason);
-    static void updateAccessibility(const QAccessibleEvent &event);
+#if QT_DEPRECATED_SINCE(5, 0)
+    QT_DEPRECATED static inline void updateAccessibility(QObject *object, int child, Event reason);
+#endif
+    static void updateAccessibility(QAccessibleEvent *event);
 
     static bool isActive();
     static void setRootObject(QObject *object);
@@ -429,25 +435,224 @@ private:
 
 class Q_GUI_EXPORT QAccessibleEvent
 {
+    Q_DISABLE_COPY(QAccessibleEvent)
 public:
-    inline QAccessibleEvent(QAccessible::Event typ, QObject *obj, int chld = -1)
-        : m_type(typ), m_object(obj), m_child(chld)
+    inline QAccessibleEvent(QObject *obj, QAccessible::Event typ)
+        : m_type(typ), m_object(obj), m_child(-1)
     {
         Q_ASSERT(obj);
+        // All events below have a subclass of QAccessibleEvent.
+        // Use the subclass, since it's expected that it's possible to cast to that.
+        Q_ASSERT(m_type != QAccessible::ValueChanged);
+        Q_ASSERT(m_type != QAccessible::StateChanged);
+        Q_ASSERT(m_type != QAccessible::TextCaretMoved);
+        Q_ASSERT(m_type != QAccessible::TextSelectionChanged);
+        Q_ASSERT(m_type != QAccessible::TextInserted);
+        Q_ASSERT(m_type != QAccessible::TextRemoved);
+        Q_ASSERT(m_type != QAccessible::TextUpdated);
+        Q_ASSERT(m_type != QAccessible::TableModelChanged);
     }
 
+    virtual ~QAccessibleEvent()
+    {}
+
     QAccessible::Event type() const { return m_type; }
     QObject *object() const { return m_object; }
+
+    void setChild(int chld) { m_child = chld; }
     int child() const { return m_child; }
 
     QAccessibleInterface *accessibleInterface() const;
 
-private:
+protected:
     QAccessible::Event m_type;
     QObject *m_object;
     int m_child;
 };
 
+class Q_GUI_EXPORT QAccessibleStateChangeEvent :public QAccessibleEvent
+{
+public:
+    inline QAccessibleStateChangeEvent(QObject *obj, QAccessible::State state)
+        : QAccessibleEvent(obj, QAccessible::InvalidEvent), m_changedStates(state)
+    {
+        m_type = QAccessible::StateChanged;
+    }
+
+    QAccessible::State changedStates() const {
+        return m_changedStates;
+    }
+
+protected:
+    QAccessible::State m_changedStates;
+};
+
+// Update the cursor and optionally the selection.
+class Q_GUI_EXPORT QAccessibleTextCursorEvent : public QAccessibleEvent
+{
+public:
+    inline QAccessibleTextCursorEvent(QObject *obj, int cursorPos)
+        : QAccessibleEvent(obj, QAccessible::InvalidEvent)
+      , m_cursorPosition(cursorPos)
+    {
+        m_type = QAccessible::TextCaretMoved;
+    }
+
+    void setCursorPosition(int position) { m_cursorPosition = position; }
+    int cursorPosition() const { return m_cursorPosition; }
+
+protected:
+    int m_cursorPosition;
+};
+
+// Updates the cursor position simultaneously. By default the cursor is set to the end of the selection.
+class Q_GUI_EXPORT QAccessibleTextSelectionEvent : public QAccessibleTextCursorEvent
+{
+public:
+    inline QAccessibleTextSelectionEvent(QObject *obj, int start, int end)
+        : QAccessibleTextCursorEvent(obj, (start == -1) ? 0 : end)
+        , m_selectionStart(start), m_selectionEnd(end)
+    {
+        m_type = QAccessible::TextSelectionChanged;
+    }
+
+    void setSelection(int start, int end) {
+        m_selectionStart = start;
+        m_selectionEnd = end;
+    }
+
+    int selectionStart() const { return m_selectionStart; }
+    int selectionEnd() const { return m_selectionEnd; }
+
+protected:
+        int m_selectionStart;
+        int m_selectionEnd;
+};
+
+class Q_GUI_EXPORT QAccessibleTextInsertEvent : public QAccessibleTextCursorEvent
+{
+public:
+    inline QAccessibleTextInsertEvent(QObject *obj, int position, const QString &text)
+        : QAccessibleTextCursorEvent(obj, position + text.length())
+        , m_position(position), m_text(text)
+    {
+        m_type = QAccessible::TextInserted;
+    }
+
+    QString textInserted() const {
+        return m_text;
+    }
+    int changePosition() const {
+        return m_position;
+    }
+
+protected:
+    int m_position;
+    QString m_text;
+};
+
+class Q_GUI_EXPORT QAccessibleTextRemoveEvent : public QAccessibleTextCursorEvent
+{
+public:
+    inline QAccessibleTextRemoveEvent(QObject *obj, int position, const QString &text)
+        : QAccessibleTextCursorEvent(obj, position)
+        , m_position(position), m_text(text)
+    {
+        m_type = QAccessible::TextRemoved;
+    }
+
+    QString textRemoved() const {
+        return m_text;
+    }
+    int changePosition() const {
+        return m_position;
+    }
+
+protected:
+    int m_position;
+    QString m_text;
+};
+
+class Q_GUI_EXPORT QAccessibleTextUpdateEvent : public QAccessibleTextCursorEvent
+{
+public:
+    inline QAccessibleTextUpdateEvent(QObject *obj, int position, const QString &oldText, const QString &text)
+        : QAccessibleTextCursorEvent(obj, position + text.length())
+        , m_position(position), m_oldText(oldText), m_text(text)
+    {
+        m_type = QAccessible::TextUpdated;
+    }
+    QString textRemoved() const {
+        return m_oldText;
+    }
+    QString textInserted() const {
+        return m_text;
+    }
+    int changePosition() const {
+        return m_position;
+    }
+
+protected:
+    int m_position;
+    QString m_oldText;
+    QString m_text;
+};
+
+class Q_GUI_EXPORT QAccessibleValueChangeEvent : public QAccessibleEvent
+{
+public:
+    inline QAccessibleValueChangeEvent(QObject *obj, const QVariant &val)
+        : QAccessibleEvent(obj, QAccessible::InvalidEvent)
+      , m_value(val)
+    {
+        m_type = QAccessible::ValueChanged;
+    }
+
+    void setValue(const QVariant & val) { m_value= val; }
+    QVariant value() const { return m_value; }
+
+protected:
+    QVariant m_value;
+};
+
+class Q_GUI_EXPORT QAccessibleTableModelChangeEvent : public QAccessibleEvent
+{
+public:
+    enum ModelChangeType {
+        ModelReset,
+        DataChanged,
+        RowsInserted,
+        ColumnsInserted,
+        RowsRemoved,
+        ColumnsRemoved
+    };
+
+    inline QAccessibleTableModelChangeEvent(QObject *obj, ModelChangeType changeType)
+        : QAccessibleEvent(obj, QAccessible::InvalidEvent)
+        , m_modelChangeType(changeType)
+        , m_firstRow(-1), m_firstColumn(-1), m_lastRow(-1), m_lastColumn(-1)
+    {
+        m_type = QAccessible::TableModelChanged;
+    }
+    void setModelChangeType(ModelChangeType changeType) { m_modelChangeType = changeType; }
+    ModelChangeType modelChangeType() const { return m_modelChangeType; }
+
+    void setFirstRow(int row) { m_firstRow = row; }
+    void setFirstColumn(int col) { m_firstColumn = col; }
+    void setLastRow(int row) { m_lastRow = row; }
+    void setLastColumn(int col) { m_lastColumn = col; }
+    int firstRow() const { return m_firstRow; }
+    int firstColumn() const { return m_firstColumn; }
+    int lastRow() const { return m_lastRow; }
+    int lastColumn() const { return m_lastColumn; }
+
+protected:
+    ModelChangeType m_modelChangeType;
+    int m_firstRow;
+    int m_firstColumn;
+    int m_lastRow;
+    int m_lastColumn;
+};
 
 #define QAccessibleInterface_iid "org.qt-project.Qt.QAccessibleInterface"
 Q_DECLARE_INTERFACE(QAccessibleInterface, QAccessibleInterface_iid)
@@ -457,9 +662,19 @@ Q_GUI_EXPORT const char *qAccessibleEventString(QAccessible::Event event);
 
 #ifndef QT_NO_DEBUG_STREAM
 Q_GUI_EXPORT QDebug operator<<(QDebug d, const QAccessibleInterface *iface);
+Q_GUI_EXPORT QDebug operator<<(QDebug d, const QAccessibleEvent &ev);
 #endif
 
-#endif // QT_NO_ACCESSIBILITY
+#if QT_DEPRECATED_SINCE(5, 0)
+inline void QAccessible::updateAccessibility(QObject *object, int child, Event reason)
+{
+    Q_ASSERT(object);
+
+    QAccessibleEvent ev(object, reason);
+    ev.setChild(child);
+    updateAccessibility(&ev);
+}
+#endif
 
 QT_END_NAMESPACE