1 /****************************************************************************
2 **
3 ** Copyright (C) 2017 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the plugins of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #include <QtGui/qtguiglobal.h>
41 #if QT_CONFIG(accessibility)
42 
43 #include "qwindowsuiagriditemprovider.h"
44 #include "qwindowsuiamainprovider.h"
45 #include "qwindowsuiautils.h"
46 #include "qwindowscontext.h"
47 
48 #include <QtGui/qaccessible.h>
49 #include <QtCore/qloggingcategory.h>
50 #include <QtCore/qstring.h>
51 
52 QT_BEGIN_NAMESPACE
53 
54 using namespace QWindowsUiAutomation;
55 
56 
QWindowsUiaGridItemProvider(QAccessible::Id id)57 QWindowsUiaGridItemProvider::QWindowsUiaGridItemProvider(QAccessible::Id id) :
58     QWindowsUiaBaseProvider(id)
59 {
60 }
61 
~QWindowsUiaGridItemProvider()62 QWindowsUiaGridItemProvider::~QWindowsUiaGridItemProvider()
63 {
64 }
65 
66 // Returns the row index of the item.
get_Row(int * pRetVal)67 HRESULT STDMETHODCALLTYPE QWindowsUiaGridItemProvider::get_Row(int *pRetVal)
68 {
69     qCDebug(lcQpaUiAutomation) << __FUNCTION__;
70 
71     if (!pRetVal)
72         return E_INVALIDARG;
73     *pRetVal = 0;
74 
75     QAccessibleInterface *accessible = accessibleInterface();
76     if (!accessible)
77         return UIA_E_ELEMENTNOTAVAILABLE;
78 
79     QAccessibleTableCellInterface *tableCellInterface = accessible->tableCellInterface();
80     if (!tableCellInterface)
81         return UIA_E_ELEMENTNOTAVAILABLE;
82 
83     *pRetVal = tableCellInterface->rowIndex();
84     return S_OK;
85 }
86 
87 // Returns the column index of the item.
get_Column(int * pRetVal)88 HRESULT STDMETHODCALLTYPE QWindowsUiaGridItemProvider::get_Column(int *pRetVal)
89 {
90     qCDebug(lcQpaUiAutomation) << __FUNCTION__;
91 
92     if (!pRetVal)
93         return E_INVALIDARG;
94     *pRetVal = 0;
95 
96     QAccessibleInterface *accessible = accessibleInterface();
97     if (!accessible)
98         return UIA_E_ELEMENTNOTAVAILABLE;
99 
100     QAccessibleTableCellInterface *tableCellInterface = accessible->tableCellInterface();
101     if (!tableCellInterface)
102         return UIA_E_ELEMENTNOTAVAILABLE;
103 
104     *pRetVal = tableCellInterface->columnIndex();
105     return S_OK;
106 }
107 
108 // Returns the number of rows occupied by the item.
get_RowSpan(int * pRetVal)109 HRESULT STDMETHODCALLTYPE QWindowsUiaGridItemProvider::get_RowSpan(int *pRetVal)
110 {
111     qCDebug(lcQpaUiAutomation) << __FUNCTION__;
112 
113     if (!pRetVal)
114         return E_INVALIDARG;
115     *pRetVal = 0;
116 
117     QAccessibleInterface *accessible = accessibleInterface();
118     if (!accessible)
119         return UIA_E_ELEMENTNOTAVAILABLE;
120 
121     QAccessibleTableCellInterface *tableCellInterface = accessible->tableCellInterface();
122     if (!tableCellInterface)
123         return UIA_E_ELEMENTNOTAVAILABLE;
124 
125     *pRetVal = tableCellInterface->rowExtent();
126     return S_OK;
127 }
128 
129 // Returns the number of columns occupied by the item.
get_ColumnSpan(int * pRetVal)130 HRESULT STDMETHODCALLTYPE QWindowsUiaGridItemProvider::get_ColumnSpan(int *pRetVal)
131 {
132     qCDebug(lcQpaUiAutomation) << __FUNCTION__;
133 
134     if (!pRetVal)
135         return E_INVALIDARG;
136     *pRetVal = 0;
137 
138     QAccessibleInterface *accessible = accessibleInterface();
139     if (!accessible)
140         return UIA_E_ELEMENTNOTAVAILABLE;
141 
142     QAccessibleTableCellInterface *tableCellInterface = accessible->tableCellInterface();
143     if (!tableCellInterface)
144         return UIA_E_ELEMENTNOTAVAILABLE;
145 
146     *pRetVal = tableCellInterface->columnExtent();
147     return S_OK;
148 }
149 
150 // Returns the provider for the containing table/tree.
get_ContainingGrid(IRawElementProviderSimple ** pRetVal)151 HRESULT STDMETHODCALLTYPE QWindowsUiaGridItemProvider::get_ContainingGrid(IRawElementProviderSimple **pRetVal)
152 {
153     qCDebug(lcQpaUiAutomation) << __FUNCTION__;
154 
155     if (!pRetVal)
156         return E_INVALIDARG;
157     *pRetVal = nullptr;
158 
159     QAccessibleInterface *accessible = accessibleInterface();
160     if (!accessible)
161         return UIA_E_ELEMENTNOTAVAILABLE;
162 
163     QAccessibleTableCellInterface *tableCellInterface = accessible->tableCellInterface();
164     if (!tableCellInterface)
165         return UIA_E_ELEMENTNOTAVAILABLE;
166 
167     if (QAccessibleInterface *table = tableCellInterface->table()) {
168         *pRetVal = QWindowsUiaMainProvider::providerForAccessible(table);
169     }
170     return S_OK;
171 }
172 
173 QT_END_NAMESPACE
174 
175 #endif // QT_CONFIG(accessibility)
176