4#include <QtGui/qtguiglobal.h>
5#if QT_CONFIG(accessibility)
7#include "qwindowsuiatextprovider.h"
8#include "qwindowsuiautils.h"
9#include "qwindowscontext.h"
11#include <QtGui/qaccessible.h>
12#include <QtCore/qloggingcategory.h>
13#include <QtCore/qstring.h>
14#include <QtCore/private/qcomptr_p.h>
17using namespace QWindowsUiAutomation;
20QWindowsUiaTextProvider::QWindowsUiaTextProvider(QAccessible::Id id) :
21 QWindowsUiaBaseProvider(id)
25QWindowsUiaTextProvider::~QWindowsUiaTextProvider()
30HRESULT STDMETHODCALLTYPE QWindowsUiaTextProvider::GetSelection(SAFEARRAY **pRetVal)
32 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
38 QAccessibleInterface *accessible = accessibleInterface();
40 return UIA_E_ELEMENTNOTAVAILABLE;
42 QAccessibleTextInterface *textInterface = accessible->textInterface();
44 return UIA_E_ELEMENTNOTAVAILABLE;
46 int selCount = textInterface->selectionCount();
49 if ((*pRetVal = SafeArrayCreateVector(VT_UNKNOWN, 0, selCount))) {
50 for (LONG i = 0; i < selCount; ++i) {
51 int startOffset = 0, endOffset = 0;
52 textInterface->selection((
int)i, &startOffset, &endOffset);
53 ComPtr<IUnknown> textRangeProvider =
54 makeComObject<QWindowsUiaTextRangeProvider>(id(), startOffset, endOffset);
55 SafeArrayPutElement(*pRetVal, &i, textRangeProvider.Get());
60 if ((*pRetVal = SafeArrayCreateVector(VT_UNKNOWN, 0, 1))) {
62 int cursorPosition = textInterface->cursorPosition();
63 ComPtr<IUnknown> textRangeProvider = makeComObject<QWindowsUiaTextRangeProvider>(
64 id(), cursorPosition, cursorPosition);
65 SafeArrayPutElement(*pRetVal, &i, textRangeProvider.Get());
72HRESULT STDMETHODCALLTYPE QWindowsUiaTextProvider::GetVisibleRanges(SAFEARRAY **pRetVal)
74 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
80 QAccessibleInterface *accessible = accessibleInterface();
82 return UIA_E_ELEMENTNOTAVAILABLE;
84 QAccessibleTextInterface *textInterface = accessible->textInterface();
86 return UIA_E_ELEMENTNOTAVAILABLE;
89 if ((*pRetVal = SafeArrayCreateVector(VT_UNKNOWN, 0, 1))) {
91 ComPtr<IUnknown> textRangeProvider =
92 makeComObject<QWindowsUiaTextRangeProvider>(id(), 0, textInterface->characterCount());
93 SafeArrayPutElement(*pRetVal, &i, textRangeProvider.Get());
98HRESULT STDMETHODCALLTYPE QWindowsUiaTextProvider::RangeFromChild(IRawElementProviderSimple * ,
99 ITextRangeProvider **pRetVal)
101 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
111HRESULT STDMETHODCALLTYPE QWindowsUiaTextProvider::RangeFromPoint(UiaPoint point, ITextRangeProvider **pRetVal)
113 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
119 QAccessibleInterface *accessible = accessibleInterface();
121 return UIA_E_ELEMENTNOTAVAILABLE;
123 QAccessibleTextInterface *textInterface = accessible->textInterface();
125 return UIA_E_ELEMENTNOTAVAILABLE;
127 QWindow *window = windowForAccessible(accessible);
129 return UIA_E_ELEMENTNOTAVAILABLE;
132 nativeUiaPointToPoint(point, window, &pt);
134 int offset = textInterface->offsetAtPoint(pt);
135 if (offset < 0 || offset >= textInterface->characterCount())
136 return UIA_E_ELEMENTNOTAVAILABLE;
138 *pRetVal = makeComObject<QWindowsUiaTextRangeProvider>(id(), offset, offset).Detach();
143HRESULT STDMETHODCALLTYPE QWindowsUiaTextProvider::get_DocumentRange(ITextRangeProvider **pRetVal)
145 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
151 QAccessibleInterface *accessible = accessibleInterface();
153 return UIA_E_ELEMENTNOTAVAILABLE;
155 QAccessibleTextInterface *textInterface = accessible->textInterface();
157 return UIA_E_ELEMENTNOTAVAILABLE;
159 *pRetVal = makeComObject<QWindowsUiaTextRangeProvider>(id(), 0, textInterface->characterCount())
165HRESULT STDMETHODCALLTYPE QWindowsUiaTextProvider::get_SupportedTextSelection(SupportedTextSelection *pRetVal)
167 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
171 *pRetVal = SupportedTextSelection_Single;
176HRESULT STDMETHODCALLTYPE QWindowsUiaTextProvider::RangeFromAnnotation(IRawElementProviderSimple * , ITextRangeProvider **pRetVal)
178 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
186HRESULT STDMETHODCALLTYPE QWindowsUiaTextProvider::GetCaretRange(BOOL *isActive, ITextRangeProvider **pRetVal)
188 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
190 if (!isActive || !pRetVal)
195 QAccessibleInterface *accessible = accessibleInterface();
197 return UIA_E_ELEMENTNOTAVAILABLE;
199 QAccessibleTextInterface *textInterface = accessible->textInterface();
201 return UIA_E_ELEMENTNOTAVAILABLE;
203 *isActive = accessible->state().focused;
205 int cursorPosition = textInterface->cursorPosition();
206 *pRetVal = makeComObject<QWindowsUiaTextRangeProvider>(id(), cursorPosition, cursorPosition)