summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/windows/accessible/iaccessible2.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/platforms/windows/accessible/iaccessible2.cpp')
-rw-r--r--src/plugins/platforms/windows/accessible/iaccessible2.cpp166
1 files changed, 96 insertions, 70 deletions
diff --git a/src/plugins/platforms/windows/accessible/iaccessible2.cpp b/src/plugins/platforms/windows/accessible/iaccessible2.cpp
index 5ed8d30e67..f34649e327 100644
--- a/src/plugins/platforms/windows/accessible/iaccessible2.cpp
+++ b/src/plugins/platforms/windows/accessible/iaccessible2.cpp
@@ -1,31 +1,37 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the plugins of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $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 The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company 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 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
@@ -41,8 +47,16 @@
#include <QtGui/qguiapplication.h>
#include <QtCore/qdebug.h>
+#include <algorithm>
+
QT_BEGIN_NAMESPACE
+template <class T>
+static inline T *coTaskMemAllocArray(int size)
+{
+ return static_cast<T *>(::CoTaskMemAlloc(sizeof(T) * size_t(size)));
+}
+
/**************************************************************\
* AccessibleApplication *
**************************************************************/
@@ -52,7 +66,7 @@ HRESULT STDMETHODCALLTYPE AccessibleApplication::QueryInterface(REFIID id, LPVOI
*iface = 0;
if (id == IID_IUnknown) {
qCDebug(lcQpaAccessibility) << "AccessibleApplication::QI(): IID_IUnknown";
- *iface = (IUnknown*)this;
+ *iface = static_cast<IUnknown *>(this);
} else if (id == IID_IAccessibleApplication) {
qCDebug(lcQpaAccessibility) << "AccessibleApplication::QI(): IID_IAccessibleApplication";
*iface = static_cast<IAccessibleApplication*>(this);
@@ -122,7 +136,7 @@ HRESULT STDMETHODCALLTYPE AccessibleRelation::QueryInterface(REFIID id, LPVOID *
{
*iface = 0;
if (id == IID_IUnknown || id == IID_IAccessibleRelation)
- *iface = (IUnknown*)this;
+ *iface = static_cast<IUnknown *>(this);
if (*iface) {
AddRef();
@@ -200,7 +214,7 @@ HRESULT STDMETHODCALLTYPE AccessibleRelation::get_targets(
/* [retval][out] */ long *nTargets)
{
- const int numTargets = qMin((int)maxTargets, m_targets.count());
+ const int numTargets = qMin(int(maxTargets), m_targets.count());
for (int i = 0; i < numTargets; ++i) {
QAccessibleInterface *iface = m_targets.at(i);
IAccessible *iacc = QWindowsAccessibility::wrap(iface);
@@ -229,42 +243,40 @@ HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::QueryInterface(REFIID id, LPVOI
HRESULT hr = QWindowsMsaaAccessible::QueryInterface(id, iface);
if (!SUCCEEDED(hr)) {
if (id == IID_IServiceProvider) {
- *iface = (IServiceProvider*)this;
+ *iface = static_cast<IServiceProvider *>(this);
} else if (id == IID_IAccessible2) {
- *iface = (IAccessible2*)this;
+ *iface = static_cast<IAccessible2 *>(this);
} else if (id == IID_IAccessibleAction) {
if (accessible->actionInterface())
- *iface = (IAccessibleAction*)this;
+ *iface = static_cast<IAccessibleAction *>(this);
} else if (id == IID_IAccessibleComponent) {
- *iface = (IAccessibleComponent*)this;
+ *iface = static_cast<IAccessibleComponent *>(this);
} else if (id == IID_IAccessibleEditableText) {
if (accessible->editableTextInterface() ||
accessible->role() == QAccessible::EditableText)
{
- *iface = (IAccessibleEditableText*)this;
+ *iface = static_cast<IAccessibleEditableText *>(this);
}
} else if (id == IID_IAccessibleHyperlink) {
- //*iface = (IAccessibleHyperlink*)this;
+ //*iface = static_cast<IAccessibleHyperlink *>(this);
} else if (id == IID_IAccessibleHypertext) {
- //*iface = (IAccessibleHypertext*)this;
+ //*iface = static_cast<IAccessibleHypertext *>(this);
} else if (id == IID_IAccessibleImage) {
- //*iface = (IAccessibleImage*)this;
- } else if (id == IID_IAccessibleRelation) {
- *iface = (IAccessibleRelation*)this;
+ //*iface = static_cast<IAccessibleImage *>(this);
} else if (id == IID_IAccessibleTable) {
- //*iface = (IAccessibleTable*)this; // not supported
+ //*iface = static_cast<IAccessibleTable *>(this); // not supported
} else if (id == IID_IAccessibleTable2) {
if (accessible->tableInterface())
- *iface = (IAccessibleTable2*)this;
+ *iface = static_cast<IAccessibleTable2 *>(this);
} else if (id == IID_IAccessibleTableCell) {
if (accessible->tableCellInterface())
- *iface = (IAccessibleTableCell*)this;
+ *iface = static_cast<IAccessibleTableCell *>(this);
} else if (id == IID_IAccessibleText) {
if (accessible->textInterface())
- *iface = (IAccessibleText*)this;
+ *iface = static_cast<IAccessibleText *>(this);
} else if (id == IID_IAccessibleValue) {
if (accessible->valueInterface())
- *iface = (IAccessibleValue*)this;
+ *iface = static_cast<IAccessibleValue *>(this);
}
if (*iface) {
AddRef();
@@ -593,9 +605,9 @@ HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::get_keyBinding(long actionIndex
numBindings = keyBindings.count();
if (numBindings > 0) {
// The IDL documents that the client must free with CoTaskMemFree
- arrayOfBindingsToReturn = (BSTR*)::CoTaskMemAlloc(sizeof(BSTR) * numBindings);
- for (int i = 0; i < numBindings; ++i)
- arrayOfBindingsToReturn[i] = QStringToBSTR(keyBindings.at(i));
+ arrayOfBindingsToReturn = coTaskMemAllocArray<BSTR>(numBindings);
+ std::transform(keyBindings.constBegin(), keyBindings.constEnd(),
+ arrayOfBindingsToReturn, QStringToBSTR);
}
}
*keyBindings = arrayOfBindingsToReturn;
@@ -668,7 +680,7 @@ HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::get_foreground(IA2Color *foregr
return E_FAIL;
// IA2Color is a typedef for long
- *foreground = (IA2Color)accessible->foregroundColor().rgb();
+ *foreground = static_cast<IA2Color>(accessible->foregroundColor().rgb());
return S_OK;
}
@@ -680,7 +692,7 @@ HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::get_background(IA2Color *backgr
return E_FAIL;
// IA2Color is a typedef for long
- *background = (IA2Color)accessible->backgroundColor().rgb();
+ *background = static_cast<IA2Color>(accessible->backgroundColor().rgb());
return S_OK;
}
@@ -754,7 +766,7 @@ HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::insertText(long offset, BSTR *t
{
QAccessibleInterface *accessible = accessibleInterface();
accessibleDebugClientCalls(accessible);
- const QString txt(BSTRToQString(*text));
+ const QString txt = QString::fromWCharArray(*text);
if (QAccessibleEditableTextInterface *editableTextIface = accessible->editableTextInterface())
editableTextIface->insertText(offset, txt);
else
@@ -799,7 +811,7 @@ HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::replaceText(long startOffset, l
{
QAccessibleInterface *accessible = accessibleInterface();
accessibleDebugClientCalls(accessible);
- const QString txt(BSTRToQString(*text));
+ const QString txt = QString::fromWCharArray(*text);
if (QAccessibleEditableTextInterface *editableTextIface = accessible->editableTextInterface())
editableTextIface->replaceText(startOffset, endOffset, txt);
else
@@ -972,12 +984,13 @@ HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::get_selectedColumns(long **sele
if (QAccessibleTableInterface *tableIface = tableInterface()) {
const QList<int> selectedIndices = tableIface->selectedColumns();
- const int &count = selectedIndices.count();
- long *selected = (count ? (long*)::CoTaskMemAlloc(sizeof(long) * count) : (long*)0);
- for (int i = 0; i < count; ++i)
- selected[i] = selectedIndices.at(i);
- *selectedColumns = selected;
+ const int count = selectedIndices.count();
*nColumns = count;
+ *selectedColumns = Q_NULLPTR;
+ if (count) {
+ *selectedColumns = coTaskMemAllocArray<long>(count);
+ std::copy(selectedIndices.constBegin(), selectedIndices.constEnd(), *selectedColumns);
+ }
return count ? S_OK : S_FALSE;
}
return E_FAIL;
@@ -993,12 +1006,13 @@ HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::get_selectedRows(long **selecte
if (QAccessibleTableInterface *tableIface = tableInterface()) {
const QList<int> selectedIndices = tableIface->selectedRows();
- const int &count = selectedIndices.count();
- long *selected = (count ? (long*)::CoTaskMemAlloc(sizeof(long) * count) : (long*)0);
- for (int i = 0; i < count; ++i)
- selected[i] = selectedIndices.at(i);
- *selectedRows = selected;
+ const int count = selectedIndices.count();
*nRows = count;
+ *selectedRows = Q_NULLPTR;
+ if (count) {
+ *selectedRows = coTaskMemAllocArray<long>(count);
+ std::copy(selectedIndices.constBegin(), selectedIndices.constEnd(), *selectedRows);
+ }
return count ? S_OK : S_FALSE;
}
return E_FAIL;
@@ -1198,10 +1212,10 @@ HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::get_rowColumnExtents(long *row,
if (!accessible || !tableCellInterface())
return E_FAIL;
- *row = (long)tableCellInterface()->rowIndex();
- *column = (long)tableCellInterface()->columnIndex();
- *rowExtents = (long)tableCellInterface()->rowExtent();
- *columnExtents = (long)tableCellInterface()->columnExtent();
+ *row = tableCellInterface()->rowIndex();
+ *column = tableCellInterface()->columnIndex();
+ *rowExtents = tableCellInterface()->rowExtent();
+ *columnExtents = tableCellInterface()->columnExtent();
*isSelected = tableCellInterface()->isSelected();
return S_OK;
}
@@ -1242,7 +1256,8 @@ HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::get_attributes(long offset,
QAccessibleInterface *accessible = accessibleInterface();
accessibleDebugClientCalls(accessible);
if (QAccessibleTextInterface *text = textInterface()) {
- const QString attrs = text->attributes(offset, (int*)startOffset, (int*)endOffset);
+ const QString attrs = text->attributes(offset, reinterpret_cast<int *>(startOffset),
+ reinterpret_cast<int *>(endOffset));
*textAttributes = QStringToBSTR(attrs);
return S_OK;
}
@@ -1314,7 +1329,8 @@ HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::get_selection(long selectionInd
QAccessibleInterface *accessible = accessibleInterface();
accessibleDebugClientCalls(accessible);
if (QAccessibleTextInterface *text = textInterface()) {
- text->selection(selectionIndex, (int*)startOffset, (int*)endOffset);
+ text->selection(selectionIndex, reinterpret_cast<int *>(startOffset),
+ reinterpret_cast<int *>(endOffset));
return S_OK;
}
return E_FAIL;
@@ -1346,7 +1362,10 @@ HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::get_textBeforeOffset(long offse
QAccessibleInterface *accessible = accessibleInterface();
accessibleDebugClientCalls(accessible);
if (QAccessibleTextInterface *textIface = textInterface()) {
- const QString txt = textIface->textBeforeOffset(offset, (QAccessible::TextBoundaryType)boundaryType, (int*)startOffset, (int*)endOffset);
+ const QString txt =
+ textIface->textBeforeOffset(offset, static_cast<QAccessible::TextBoundaryType>(boundaryType),
+ reinterpret_cast<int *>(startOffset),
+ reinterpret_cast<int *>(endOffset));
if (!txt.isEmpty()) {
*text = QStringToBSTR(txt);
return S_OK;
@@ -1366,7 +1385,10 @@ HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::get_textAfterOffset(
QAccessibleInterface *accessible = accessibleInterface();
accessibleDebugClientCalls(accessible);
if (QAccessibleTextInterface *textIface = textInterface()) {
- const QString txt = textIface->textAfterOffset(offset, (QAccessible::TextBoundaryType)boundaryType, (int*)startOffset, (int*)endOffset);
+ const QString txt =
+ textIface->textAfterOffset(offset, static_cast<QAccessible::TextBoundaryType>(boundaryType),
+ reinterpret_cast<int *>(startOffset),
+ reinterpret_cast<int *>(endOffset));
if (!txt.isEmpty()) {
*text = QStringToBSTR(txt);
return S_OK;
@@ -1385,7 +1407,10 @@ HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::get_textAtOffset(long offset,
QAccessibleInterface *accessible = accessibleInterface();
accessibleDebugClientCalls(accessible);
if (QAccessibleTextInterface *textIface = textInterface()) {
- const QString txt = textIface->textAtOffset(offset, (QAccessible::TextBoundaryType)boundaryType, (int*)startOffset, (int*)endOffset);
+ const QString txt =
+ textIface->textAtOffset(offset, static_cast<QAccessible::TextBoundaryType>(boundaryType),
+ reinterpret_cast<int *>(startOffset),
+ reinterpret_cast<int *>(endOffset));
if (!txt.isEmpty()) {
*text = QStringToBSTR(txt);
return S_OK;
@@ -1624,7 +1649,7 @@ HRESULT QWindowsIA2Accessible::getRelationsHelper(IAccessibleRelation **relation
QList<QAccessible::Relation> keys = relationMap.keys();
const int numRelations = keys.count();
if (relations) {
- for (int i = startIndex; i < qMin(startIndex + (int)maxRelations, numRelations); ++i) {
+ for (int i = startIndex; i < qMin(startIndex + int(maxRelations), numRelations); ++i) {
QAccessible::Relation relation = keys.at(i);
QList<QAccessibleInterface*> targets = relationMap.values(relation);
AccessibleRelation *rel = new AccessibleRelation(targets, relation);
@@ -1650,12 +1675,13 @@ HRESULT QWindowsIA2Accessible::wrapListOfCells(const QList<QAccessibleInterface*
{
const int count = inputCells.count();
// Server allocates array
- IUnknown **outputCells = count ? (IUnknown**)::CoTaskMemAlloc(sizeof(IUnknown*) * count ) : (IUnknown**)0;
- for (int i = 0; i < count; ++i)
- outputCells[i] = QWindowsAccessibility::wrap(inputCells.at(i));
-
- *outputAccessibles = outputCells;
*nCellCount = count;
+ *outputAccessibles = Q_NULLPTR;
+ if (count) {
+ *outputAccessibles = coTaskMemAllocArray<IUnknown *>(count);
+ std::transform(inputCells.constBegin(), inputCells.constEnd(),
+ *outputAccessibles, QWindowsAccessibility::wrap);
+ }
return count > 0 ? S_OK : S_FALSE;
}
@@ -1699,12 +1725,12 @@ QByteArray QWindowsIA2Accessible::IIDToString(REFIID id)
}
// Q_STATIC_ASSERT(IA2_ROLE_CANVAS == QAccessible::Canvas); // ### Qt 6: make them the same
-Q_STATIC_ASSERT(IA2_ROLE_COLOR_CHOOSER == QAccessible::ColorChooser);
-Q_STATIC_ASSERT(IA2_ROLE_FOOTER == QAccessible::Footer);
-Q_STATIC_ASSERT(IA2_ROLE_FORM == QAccessible::Form);
-Q_STATIC_ASSERT(IA2_ROLE_HEADING == QAccessible::Heading);
-Q_STATIC_ASSERT(IA2_ROLE_NOTE == QAccessible::Note);
-Q_STATIC_ASSERT(IA2_ROLE_COMPLEMENTARY_CONTENT == QAccessible::ComplementaryContent);
+Q_STATIC_ASSERT(IA2_ROLE_COLOR_CHOOSER == static_cast<IA2Role>(QAccessible::ColorChooser));
+Q_STATIC_ASSERT(IA2_ROLE_FOOTER == static_cast<IA2Role>(QAccessible::Footer));
+Q_STATIC_ASSERT(IA2_ROLE_FORM == static_cast<IA2Role>(QAccessible::Form));
+Q_STATIC_ASSERT(IA2_ROLE_HEADING == static_cast<IA2Role>(QAccessible::Heading));
+Q_STATIC_ASSERT(IA2_ROLE_NOTE == static_cast<IA2Role>(QAccessible::Note));
+Q_STATIC_ASSERT(IA2_ROLE_COMPLEMENTARY_CONTENT == static_cast<IA2Role>(QAccessible::ComplementaryContent));
QT_END_NAMESPACE