5#include <QtGui/qtguiglobal.h>
6#if QT_CONFIG(accessibility)
8#include "qwindowsuiatextprovider.h"
9#include "qwindowsuiautils.h"
10#include "qwindowscontext.h"
12#include <QtGui/qaccessible.h>
13#include <QtCore/qloggingcategory.h>
14#include <QtCore/qstring.h>
15#include <QtCore/private/qcomptr_p.h>
18using namespace QWindowsUiAutomation;
21QWindowsUiaTextProvider::QWindowsUiaTextProvider(QAccessible::Id id) :
22 QWindowsUiaBaseProvider(id)
26QWindowsUiaTextProvider::~QWindowsUiaTextProvider()
31HRESULT STDMETHODCALLTYPE QWindowsUiaTextProvider::GetSelection(SAFEARRAY **pRetVal)
33 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
39 QAccessibleInterface *accessible = accessibleInterface();
41 return UIA_E_ELEMENTNOTAVAILABLE;
43 QAccessibleTextInterface *textInterface = accessible->textInterface();
45 return UIA_E_ELEMENTNOTAVAILABLE;
47 int selCount = textInterface->selectionCount();
50 if ((*pRetVal = SafeArrayCreateVector(VT_UNKNOWN, 0, selCount))) {
51 for (LONG i = 0; i < selCount; ++i) {
52 int startOffset = 0, endOffset = 0;
53 textInterface->selection((
int)i, &startOffset, &endOffset);
54 ComPtr<IUnknown> textRangeProvider =
55 makeComObject<QWindowsUiaTextRangeProvider>(id(), startOffset, endOffset);
56 SafeArrayPutElement(*pRetVal, &i, textRangeProvider.Get());
61 if ((*pRetVal = SafeArrayCreateVector(VT_UNKNOWN, 0, 1))) {
63 int cursorPosition = textInterface->cursorPosition();
64 ComPtr<IUnknown> textRangeProvider = makeComObject<QWindowsUiaTextRangeProvider>(
65 id(), cursorPosition, cursorPosition);
66 SafeArrayPutElement(*pRetVal, &i, textRangeProvider.Get());
73HRESULT STDMETHODCALLTYPE QWindowsUiaTextProvider::GetVisibleRanges(SAFEARRAY **pRetVal)
75 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
81 QAccessibleInterface *accessible = accessibleInterface();
83 return UIA_E_ELEMENTNOTAVAILABLE;
85 QAccessibleTextInterface *textInterface = accessible->textInterface();
87 return UIA_E_ELEMENTNOTAVAILABLE;
90 if ((*pRetVal = SafeArrayCreateVector(VT_UNKNOWN, 0, 1))) {
92 ComPtr<IUnknown> textRangeProvider =
93 makeComObject<QWindowsUiaTextRangeProvider>(id(), 0, textInterface->characterCount());
94 SafeArrayPutElement(*pRetVal, &i, textRangeProvider.Get());
99HRESULT STDMETHODCALLTYPE QWindowsUiaTextProvider::RangeFromChild(IRawElementProviderSimple * ,
100 ITextRangeProvider **pRetVal)
102 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
112HRESULT STDMETHODCALLTYPE QWindowsUiaTextProvider::RangeFromPoint(UiaPoint point, ITextRangeProvider **pRetVal)
114 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
120 QAccessibleInterface *accessible = accessibleInterface();
122 return UIA_E_ELEMENTNOTAVAILABLE;
124 QAccessibleTextInterface *textInterface = accessible->textInterface();
126 return UIA_E_ELEMENTNOTAVAILABLE;
128 QWindow *window = windowForAccessible(accessible);
130 return UIA_E_ELEMENTNOTAVAILABLE;
133 nativeUiaPointToPoint(point, window, &pt);
135 int offset = textInterface->offsetAtPoint(pt);
136 if (offset < 0 || offset >= textInterface->characterCount())
137 return UIA_E_ELEMENTNOTAVAILABLE;
139 *pRetVal = makeComObject<QWindowsUiaTextRangeProvider>(id(), offset, offset).Detach();
144HRESULT STDMETHODCALLTYPE QWindowsUiaTextProvider::get_DocumentRange(ITextRangeProvider **pRetVal)
146 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
152 QAccessibleInterface *accessible = accessibleInterface();
154 return UIA_E_ELEMENTNOTAVAILABLE;
156 QAccessibleTextInterface *textInterface = accessible->textInterface();
158 return UIA_E_ELEMENTNOTAVAILABLE;
160 *pRetVal = makeComObject<QWindowsUiaTextRangeProvider>(id(), 0, textInterface->characterCount())
166HRESULT STDMETHODCALLTYPE QWindowsUiaTextProvider::get_SupportedTextSelection(SupportedTextSelection *pRetVal)
168 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
172 *pRetVal = SupportedTextSelection_Single;
177HRESULT STDMETHODCALLTYPE QWindowsUiaTextProvider::RangeFromAnnotation(IRawElementProviderSimple * , ITextRangeProvider **pRetVal)
179 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
187HRESULT STDMETHODCALLTYPE QWindowsUiaTextProvider::GetCaretRange(BOOL *isActive, ITextRangeProvider **pRetVal)
189 qCDebug(lcQpaUiAutomation) <<
__FUNCTION__ <<
this;
191 if (!isActive || !pRetVal)
196 QAccessibleInterface *accessible = accessibleInterface();
198 return UIA_E_ELEMENTNOTAVAILABLE;
200 QAccessibleTextInterface *textInterface = accessible->textInterface();
202 return UIA_E_ELEMENTNOTAVAILABLE;
204 *isActive = accessible->state().focused;
206 int cursorPosition = textInterface->cursorPosition();
207 *pRetVal = makeComObject<QWindowsUiaTextRangeProvider>(id(), cursorPosition, cursorPosition)