summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/windows/accessible/iaccessible2.h
blob: 0f9d3b3c41f58a2d7b2dca82d97ccd28f88bd997 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** 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.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia 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.
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef IACCESSIBLE2_H
#define IACCESSIBLE2_H

#include <QtCore/QtConfig>
#ifndef QT_NO_ACCESSIBILITY

#include "qwindowsmsaaaccessible.h"
#include "comutils.h"

#include "Accessible2.h"
#include "AccessibleAction.h"
#include "AccessibleApplication.h"
#include "AccessibleComponent.h"
#include "AccessibleEditableText.h"
#include "AccessibleHyperlink.h"
#include "AccessibleHypertext.h"
#include "AccessibleImage.h"
#include "AccessibleRelation.h"
#include "AccessibleTable.h"
#include "AccessibleTable2.h"
#include "AccessibleTableCell.h"
#include "AccessibleText.h"
#include "AccessibleValue.h"

#include "AccessibleEventID.h"
#include "AccessibleRole.h"
#include "AccessibleStates.h"

#include <servprov.h>

QT_BEGIN_NAMESPACE

class QWindowsIA2Accessible : public QWindowsMsaaAccessible,
        public IAccessibleAction,
        public IAccessibleComponent,
        /*public IAccessibleEditableText,*/
        public IAccessibleTable2,
        public IAccessibleTableCell,
        public IAccessibleText,
        public IAccessibleValue,
        public IServiceProvider
{
public:
    QWindowsIA2Accessible(QAccessibleInterface *a) : QWindowsMsaaAccessible(a) {}

    /* IUnknown */
    HRESULT STDMETHODCALLTYPE QueryInterface(REFIID, LPVOID *);
    ULONG STDMETHODCALLTYPE AddRef();
    ULONG STDMETHODCALLTYPE Release();

    /* IAccessible2 */
    HRESULT STDMETHODCALLTYPE get_nRelations(long *nRelations);
    HRESULT STDMETHODCALLTYPE get_relation(long relationIndex, IAccessibleRelation **relation);
    HRESULT STDMETHODCALLTYPE get_relations(long maxRelations, IAccessibleRelation **relations, long *nRelations);
    HRESULT STDMETHODCALLTYPE role(long *role);
    HRESULT STDMETHODCALLTYPE scrollTo(enum IA2ScrollType scrollType);
    HRESULT STDMETHODCALLTYPE scrollToPoint(enum IA2CoordinateType coordinateType, long x, long y);
    HRESULT STDMETHODCALLTYPE get_groupPosition(long *groupLevel, long *similarItemsInGroup, long *positionInGroup);
    HRESULT STDMETHODCALLTYPE get_states(AccessibleStates *states);
    HRESULT STDMETHODCALLTYPE get_extendedRole(BSTR *extendedRole);
    HRESULT STDMETHODCALLTYPE get_localizedExtendedRole(BSTR *localizedExtendedRole);
    HRESULT STDMETHODCALLTYPE get_nExtendedStates(long *nExtendedStates);
    HRESULT STDMETHODCALLTYPE get_extendedStates(long maxExtendedStates, BSTR **extendedStates, long *nExtendedStates);
    HRESULT STDMETHODCALLTYPE get_localizedExtendedStates(long maxLocalizedExtendedStates, BSTR **localizedExtendedStates, long *nLocalizedExtendedStates);
    HRESULT STDMETHODCALLTYPE get_uniqueID(long *uniqueID);
    HRESULT STDMETHODCALLTYPE get_windowHandle(HWND *windowHandle);
    HRESULT STDMETHODCALLTYPE get_indexInParent(long *indexInParent);
    HRESULT STDMETHODCALLTYPE get_locale(IA2Locale *locale);
    HRESULT STDMETHODCALLTYPE get_attributes(BSTR *attributes);

    /* IAccessibleAction */
    HRESULT STDMETHODCALLTYPE nActions(long *nActions);
    HRESULT STDMETHODCALLTYPE doAction(long actionIndex);
    HRESULT STDMETHODCALLTYPE get_description(long actionIndex, BSTR *description);
    HRESULT STDMETHODCALLTYPE get_keyBinding(long actionIndex, long nMaxBindings, BSTR **keyBindings, long *nBindings);
    HRESULT STDMETHODCALLTYPE get_name(long actionIndex, BSTR *name);
    HRESULT STDMETHODCALLTYPE get_localizedName(long actionIndex, BSTR *localizedName);

    /* IAccessibleComponent */
    HRESULT STDMETHODCALLTYPE get_locationInParent(long *x,long *y);
    HRESULT STDMETHODCALLTYPE get_foreground(IA2Color *foreground);
    HRESULT STDMETHODCALLTYPE get_background(IA2Color *background);

    /* IAccessibleEditableText */
    /*
    HRESULT STDMETHODCALLTYPE copyText(long startOffset, long endOffset);
    HRESULT STDMETHODCALLTYPE deleteText(long startOffset, long endOffset);
    HRESULT STDMETHODCALLTYPE insertText(long offset, BSTR *text);
    HRESULT STDMETHODCALLTYPE cutText(long startOffset, long endOffset);
    HRESULT STDMETHODCALLTYPE pasteText(long offset);
    HRESULT STDMETHODCALLTYPE replaceText(long startOffset, long endOffset, BSTR *text);
    HRESULT STDMETHODCALLTYPE setAttributes(long startOffset, long endOffset, BSTR *attributes);
    */

    /* IAccessibleTable2 */
    HRESULT STDMETHODCALLTYPE get_cellAt( long row, long column, IUnknown **cell);
    HRESULT STDMETHODCALLTYPE get_caption( IUnknown **accessible);
    HRESULT STDMETHODCALLTYPE get_columnDescription( long column, BSTR *description);
    HRESULT STDMETHODCALLTYPE get_nColumns( long *columnCount);
    HRESULT STDMETHODCALLTYPE get_nRows( long *rowCount);
    HRESULT STDMETHODCALLTYPE get_nSelectedCells( long *cellCount);
    HRESULT STDMETHODCALLTYPE get_nSelectedColumns( long *columnCount);
    HRESULT STDMETHODCALLTYPE get_nSelectedRows( long *rowCount);
    HRESULT STDMETHODCALLTYPE get_rowDescription( long row, BSTR *description);
    HRESULT STDMETHODCALLTYPE get_selectedCells( IUnknown ***cells, long *nSelectedCells);
    HRESULT STDMETHODCALLTYPE get_selectedColumns( long **selectedColumns, long *nColumns);
    HRESULT STDMETHODCALLTYPE get_selectedRows( long **selectedRows, long *nRows);
    HRESULT STDMETHODCALLTYPE get_summary( IUnknown **accessible);
    HRESULT STDMETHODCALLTYPE get_isColumnSelected( long column, boolean *isSelected);
    HRESULT STDMETHODCALLTYPE get_isRowSelected( long row, boolean *isSelected);
    HRESULT STDMETHODCALLTYPE selectRow( long row);
    HRESULT STDMETHODCALLTYPE selectColumn( long column);
    HRESULT STDMETHODCALLTYPE unselectRow( long row);
    HRESULT STDMETHODCALLTYPE unselectColumn( long column);
    HRESULT STDMETHODCALLTYPE get_modelChange( IA2TableModelChange *modelChange);

    /* IAccessibleTableCell */
    HRESULT STDMETHODCALLTYPE get_columnExtent(long *nColumnsSpanned);
    HRESULT STDMETHODCALLTYPE get_columnHeaderCells(IUnknown ***cellAccessibles, long *nColumnHeaderCells);
    HRESULT STDMETHODCALLTYPE get_columnIndex(long *columnIndex);
    HRESULT STDMETHODCALLTYPE get_rowExtent(long *nRowsSpanned);
    HRESULT STDMETHODCALLTYPE get_rowHeaderCells(IUnknown ***cellAccessibles, long *nRowHeaderCells);
    HRESULT STDMETHODCALLTYPE get_rowIndex(long *rowIndex);
    HRESULT STDMETHODCALLTYPE get_isSelected( boolean *isSelected);
    HRESULT STDMETHODCALLTYPE get_rowColumnExtents(long *row, long *column,
                                                   long *rowExtents, long *columnExtents,
                                                   boolean *isSelected);
    HRESULT STDMETHODCALLTYPE get_table(IUnknown **table);


    /* IAccessibleText */
    HRESULT STDMETHODCALLTYPE addSelection(long startOffset, long endOffset);
    HRESULT STDMETHODCALLTYPE get_attributes(long offset, long *startOffset,
                                             long *endOffset, BSTR *textAttributes);
    HRESULT STDMETHODCALLTYPE get_caretOffset(long *offset);
    HRESULT STDMETHODCALLTYPE get_characterExtents(long offset, enum IA2CoordinateType coordType,
                                                   long *x, long *y,
                                                   long *width, long *height);
    HRESULT STDMETHODCALLTYPE get_nSelections(long *nSelections);
    HRESULT STDMETHODCALLTYPE get_offsetAtPoint(long x, long y, enum IA2CoordinateType coordType, long *offset);
    HRESULT STDMETHODCALLTYPE get_selection(long selectionIndex, long *startOffset, long *endOffset);
    HRESULT STDMETHODCALLTYPE get_text(long startOffset, long endOffset, BSTR *text);
    HRESULT STDMETHODCALLTYPE get_textBeforeOffset(long offset, enum IA2TextBoundaryType boundaryType,
                                                   long *startOffset, long *endOffset, BSTR *text);
    HRESULT STDMETHODCALLTYPE get_textAfterOffset(long offset, enum IA2TextBoundaryType boundaryType,
                                                  long *startOffset, long *endOffset, BSTR *text);
    HRESULT STDMETHODCALLTYPE get_textAtOffset(long offset, enum IA2TextBoundaryType boundaryType,
                                               long *startOffset, long *endOffset, BSTR *text);
    HRESULT STDMETHODCALLTYPE removeSelection(long selectionIndex);
    HRESULT STDMETHODCALLTYPE setCaretOffset(long offset);
    HRESULT STDMETHODCALLTYPE setSelection(long selectionIndex, long startOffset, long endOffset);
    HRESULT STDMETHODCALLTYPE get_nCharacters(long *nCharacters);
    HRESULT STDMETHODCALLTYPE scrollSubstringTo(long startIndex, long endIndex, enum IA2ScrollType scrollType);
    HRESULT STDMETHODCALLTYPE scrollSubstringToPoint(long startIndex, long endIndex,
                                                     enum IA2CoordinateType coordinateType, long x, long y);
    HRESULT STDMETHODCALLTYPE get_newText(IA2TextSegment *newText);
    HRESULT STDMETHODCALLTYPE get_oldText(IA2TextSegment *oldText);

    /* IAccessibleValue */
    HRESULT STDMETHODCALLTYPE get_currentValue(VARIANT *currentValue);
    HRESULT STDMETHODCALLTYPE setCurrentValue(VARIANT value);
    HRESULT STDMETHODCALLTYPE get_maximumValue(VARIANT *maximumValue);
    HRESULT STDMETHODCALLTYPE get_minimumValue(VARIANT *minimumValue);

    /* IServiceProvider */
    HRESULT STDMETHODCALLTYPE QueryService(REFGUID guidService, REFIID riid, void **ppv);

    /* private helper functions */
private:
    inline QAccessibleTextInterface *textInterface() const {
        return accessible->isValid() ? accessible->textInterface() : static_cast<QAccessibleTextInterface *>(0);
    }

    inline QAccessibleActionInterface *actionInterface() const {
        return accessible->actionInterface();
    }

    inline QAccessibleValueInterface *valueInterface() const {
        return accessible->valueInterface();
    }

    inline QAccessibleTableInterface *tableInterface() const {
        return accessible->tableInterface();
    }

    inline QAccessibleTableCellInterface *tableCellInterface() const {
        return accessible->tableCellInterface();
    }

    /*!
      \internal
      \a screenPos is in screen relative position
      \a x and \y (out) is in parent relative position if coordType == IA2_COORDTYPE_PARENT_RELATIVE
    */
    void mapFromScreenPos(enum IA2CoordinateType coordType, const QPoint &screenPos, long *x, long *y) const {
        if (coordType == IA2_COORDTYPE_PARENT_RELATIVE) {
            // caller wants relative to parent
            if (QAccessibleInterface *parent = accessible->parent()) {
                const QRect parentScreenRect = parent->rect();
                *x = parentScreenRect.x() - screenPos.x();
                *y = parentScreenRect.y() - screenPos.y();
                return;
            }
        }
        *x = screenPos.x();
        *y = screenPos.y();
    }

    /*!
      \internal
      \a x and \y is in parent relative position if coordType == IA2_COORDTYPE_PARENT_RELATIVE
      \return a screen relative position
    */
    QPoint mapToScreenPos(enum IA2CoordinateType coordType, long x, long y) const {
        if (coordType == IA2_COORDTYPE_PARENT_RELATIVE) {
            if (QAccessibleInterface *parent = accessible->parent()) {
                const QRect parentScreenRect = parent->rect();
                return QPoint(parentScreenRect.x() + x, parentScreenRect.y() + y);
            }
        }
        return QPoint(x,y);
    }

    HRESULT getRelationsHelper(IAccessibleRelation **relations, int startIndex, long maxRelations, long *nRelations = 0);
    HRESULT wrapListOfCells(const QList<QAccessibleInterface*> &inputCells, IUnknown ***outputAccessibles, long *nCellCount);
    uint uniqueID() const;
    QByteArray IIDToString(REFIID id);

};

/**************************************************************\
 *                     AccessibleApplication                  *
 **************************************************************/
class AccessibleApplication : public IAccessibleApplication
{
public:
    AccessibleApplication() : m_ref(1)
    {

    }

    virtual ~AccessibleApplication() {}

    /* IUnknown */
    HRESULT STDMETHODCALLTYPE QueryInterface(REFIID, LPVOID *);
    ULONG STDMETHODCALLTYPE AddRef();
    ULONG STDMETHODCALLTYPE Release();

    /* IAccessibleApplication */
    HRESULT STDMETHODCALLTYPE get_appName(/* [retval][out] */ BSTR *name);
    HRESULT STDMETHODCALLTYPE get_appVersion(/* [retval][out] */ BSTR *version);
    HRESULT STDMETHODCALLTYPE get_toolkitName(/* [retval][out] */ BSTR *name);
    HRESULT STDMETHODCALLTYPE get_toolkitVersion(/* [retval][out] */ BSTR *version);
private:
    ULONG m_ref;
};



/**************************************************************\
 *                     AccessibleRelation                      *
 **************************************************************/
class AccessibleRelation : public IAccessibleRelation
{
public:
    AccessibleRelation(const QList<QAccessibleInterface *> &targets,
                       QAccessible::Relation relation);

    virtual ~AccessibleRelation() {}

    /* IUnknown */
    HRESULT STDMETHODCALLTYPE QueryInterface(REFIID id, LPVOID *iface);
    ULONG STDMETHODCALLTYPE AddRef();
    ULONG STDMETHODCALLTYPE Release();

    /* IAccessibleRelation */
    HRESULT STDMETHODCALLTYPE get_relationType(BSTR *relationType);
    HRESULT STDMETHODCALLTYPE get_localizedRelationType(BSTR *localizedRelationType);
    HRESULT STDMETHODCALLTYPE get_nTargets(long *nTargets);
    HRESULT STDMETHODCALLTYPE get_target(long targetIndex, IUnknown **target);
    HRESULT STDMETHODCALLTYPE get_targets(long maxTargets, IUnknown **targets, long *nTargets);

private:
    static BSTR relationToBSTR(QAccessible::Relation relation)
    {
        wchar_t *constRelationString = 0;
        switch (relation) {
        case QAccessible::Controlled:
            constRelationString = IA2_RELATION_CONTROLLED_BY;
            break;
        }

        if (constRelationString) {
            BSTR bstrVal;
            const UINT wlen = (UINT)wcslen(constRelationString);
            bstrVal = ::SysAllocStringLen(constRelationString, wlen);
            return bstrVal;
        }
        return 0;
    }


    QList<QAccessibleInterface *> m_targets;
    QAccessible::Relation m_relation;
    ULONG m_ref;
};

QT_END_NAMESPACE

#endif //QT_NO_ACCESSIBILITY

#endif // IACCESSIBLE2_H