Windows Accessibility: Refactor code creating COM arrays.
Introduce a convenience function for allocating arrays and use algorithms. Task-number: QTBUG-50804 Change-Id: Iead75f8297923fd13efcfc7987f76262777d074b Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
This commit is contained in:
parent
7984f24b1f
commit
403b7d4a21
@ -41,8 +41,16 @@
|
|||||||
#include <QtGui/qguiapplication.h>
|
#include <QtGui/qguiapplication.h>
|
||||||
#include <QtCore/qdebug.h>
|
#include <QtCore/qdebug.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
static inline T *coTaskMemAllocArray(int size)
|
||||||
|
{
|
||||||
|
return static_cast<T *>(::CoTaskMemAlloc(sizeof(T) * size_t(size)));
|
||||||
|
}
|
||||||
|
|
||||||
/**************************************************************\
|
/**************************************************************\
|
||||||
* AccessibleApplication *
|
* AccessibleApplication *
|
||||||
**************************************************************/
|
**************************************************************/
|
||||||
@ -591,9 +599,9 @@ HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::get_keyBinding(long actionIndex
|
|||||||
numBindings = keyBindings.count();
|
numBindings = keyBindings.count();
|
||||||
if (numBindings > 0) {
|
if (numBindings > 0) {
|
||||||
// The IDL documents that the client must free with CoTaskMemFree
|
// The IDL documents that the client must free with CoTaskMemFree
|
||||||
arrayOfBindingsToReturn = (BSTR*)::CoTaskMemAlloc(sizeof(BSTR) * numBindings);
|
arrayOfBindingsToReturn = coTaskMemAllocArray<BSTR>(numBindings);
|
||||||
for (int i = 0; i < numBindings; ++i)
|
std::transform(keyBindings.constBegin(), keyBindings.constEnd(),
|
||||||
arrayOfBindingsToReturn[i] = QStringToBSTR(keyBindings.at(i));
|
arrayOfBindingsToReturn, QStringToBSTR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*keyBindings = arrayOfBindingsToReturn;
|
*keyBindings = arrayOfBindingsToReturn;
|
||||||
@ -970,12 +978,13 @@ HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::get_selectedColumns(long **sele
|
|||||||
|
|
||||||
if (QAccessibleTableInterface *tableIface = tableInterface()) {
|
if (QAccessibleTableInterface *tableIface = tableInterface()) {
|
||||||
const QList<int> selectedIndices = tableIface->selectedColumns();
|
const QList<int> selectedIndices = tableIface->selectedColumns();
|
||||||
const int &count = selectedIndices.count();
|
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;
|
|
||||||
*nColumns = 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 count ? S_OK : S_FALSE;
|
||||||
}
|
}
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
@ -991,12 +1000,13 @@ HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::get_selectedRows(long **selecte
|
|||||||
|
|
||||||
if (QAccessibleTableInterface *tableIface = tableInterface()) {
|
if (QAccessibleTableInterface *tableIface = tableInterface()) {
|
||||||
const QList<int> selectedIndices = tableIface->selectedRows();
|
const QList<int> selectedIndices = tableIface->selectedRows();
|
||||||
const int &count = selectedIndices.count();
|
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;
|
|
||||||
*nRows = 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 count ? S_OK : S_FALSE;
|
||||||
}
|
}
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
@ -1648,12 +1658,13 @@ HRESULT QWindowsIA2Accessible::wrapListOfCells(const QList<QAccessibleInterface*
|
|||||||
{
|
{
|
||||||
const int count = inputCells.count();
|
const int count = inputCells.count();
|
||||||
// Server allocates array
|
// 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;
|
*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;
|
return count > 0 ? S_OK : S_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user