diff --git a/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.cpp b/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.cpp index 3d4a03f7e9a..6efefff599a 100644 --- a/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.cpp +++ b/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.cpp @@ -271,31 +271,31 @@ HRESULT QWindowsUiaMainProvider::GetPatternProvider(PATTERNID idPattern, IUnknow switch (idPattern) { case UIA_WindowPatternId: if (accessible->parent() && (accessible->parent()->role() == QAccessible::Application)) { - *pRetVal = new QWindowsUiaWindowProvider(id()); + *pRetVal = makeComObject(id()).Detach(); } break; case UIA_TextPatternId: case UIA_TextPattern2Id: // All text controls. if (accessible->textInterface()) { - *pRetVal = new QWindowsUiaTextProvider(id()); + *pRetVal = makeComObject(id()).Detach(); } break; case UIA_ValuePatternId: // All non-static controls support the Value pattern. if (accessible->role() != QAccessible::StaticText) - *pRetVal = new QWindowsUiaValueProvider(id()); + *pRetVal = makeComObject(id()).Detach(); break; case UIA_RangeValuePatternId: // Controls providing a numeric value within a range (e.g., sliders, scroll bars, dials). if (accessible->valueInterface()) { - *pRetVal = new QWindowsUiaRangeValueProvider(id()); + *pRetVal = makeComObject(id()).Detach(); } break; case UIA_TogglePatternId: // Checkboxes and other checkable controls. if (accessible->state().checkable) - *pRetVal = new QWindowsUiaToggleProvider(id()); + *pRetVal = makeComObject(id()).Detach(); break; case UIA_SelectionPatternId: case UIA_SelectionPattern2Id: @@ -303,7 +303,7 @@ HRESULT QWindowsUiaMainProvider::GetPatternProvider(PATTERNID idPattern, IUnknow if (accessible->selectionInterface() || accessible->role() == QAccessible::List || accessible->role() == QAccessible::PageTabList) { - *pRetVal = new QWindowsUiaSelectionProvider(id()); + *pRetVal = makeComObject(id()).Detach(); } break; case UIA_SelectionItemPatternId: @@ -312,41 +312,41 @@ HRESULT QWindowsUiaMainProvider::GetPatternProvider(PATTERNID idPattern, IUnknow || (accessible->role() == QAccessible::RadioButton) || (accessible->role() == QAccessible::ListItem) || (accessible->role() == QAccessible::PageTab)) { - *pRetVal = new QWindowsUiaSelectionItemProvider(id()); + *pRetVal = makeComObject(id()).Detach(); } break; case UIA_TablePatternId: // Table/tree. if (accessible->tableInterface() && ((accessible->role() == QAccessible::Table) || (accessible->role() == QAccessible::Tree))) { - *pRetVal = new QWindowsUiaTableProvider(id()); + *pRetVal = makeComObject(id()).Detach(); } break; case UIA_TableItemPatternId: // Item within a table/tree. if (accessible->tableCellInterface() && ((accessible->role() == QAccessible::Cell) || (accessible->role() == QAccessible::TreeItem))) { - *pRetVal = new QWindowsUiaTableItemProvider(id()); + *pRetVal = makeComObject(id()).Detach(); } break; case UIA_GridPatternId: // Table/tree. if (accessible->tableInterface() && ((accessible->role() == QAccessible::Table) || (accessible->role() == QAccessible::Tree))) { - *pRetVal = new QWindowsUiaGridProvider(id()); + *pRetVal = makeComObject(id()).Detach(); } break; case UIA_GridItemPatternId: // Item within a table/tree. if (accessible->tableCellInterface() && ((accessible->role() == QAccessible::Cell) || (accessible->role() == QAccessible::TreeItem))) { - *pRetVal = new QWindowsUiaGridItemProvider(id()); + *pRetVal = makeComObject(id()).Detach(); } break; case UIA_InvokePatternId: // Things that have an invokable action (e.g., simple buttons). if (accessible->actionInterface()) { - *pRetVal = new QWindowsUiaInvokeProvider(id()); + *pRetVal = makeComObject(id()).Detach(); } break; case UIA_ExpandCollapsePatternId: @@ -356,7 +356,7 @@ HRESULT QWindowsUiaMainProvider::GetPatternProvider(PATTERNID idPattern, IUnknow && accessible->child(0)->role() == QAccessible::PopupMenu) || accessible->role() == QAccessible::ComboBox || (accessible->role() == QAccessible::TreeItem && accessible->state().expandable)) { - *pRetVal = new QWindowsUiaExpandCollapseProvider(id()); + *pRetVal = makeComObject(id()).Detach(); } break; default: diff --git a/src/plugins/platforms/windows/uiautomation/qwindowsuiatextprovider.cpp b/src/plugins/platforms/windows/uiautomation/qwindowsuiatextprovider.cpp index 172836232e1..00c2dfbd13e 100644 --- a/src/plugins/platforms/windows/uiautomation/qwindowsuiatextprovider.cpp +++ b/src/plugins/platforms/windows/uiautomation/qwindowsuiatextprovider.cpp @@ -11,7 +11,7 @@ #include #include #include - +#include QT_BEGIN_NAMESPACE using namespace QWindowsUiAutomation; @@ -50,9 +50,9 @@ HRESULT STDMETHODCALLTYPE QWindowsUiaTextProvider::GetSelection(SAFEARRAY **pRet for (LONG i = 0; i < selCount; ++i) { int startOffset = 0, endOffset = 0; textInterface->selection((int)i, &startOffset, &endOffset); - auto *textRangeProvider = new QWindowsUiaTextRangeProvider(id(), startOffset, endOffset); - SafeArrayPutElement(*pRetVal, &i, static_cast(textRangeProvider)); - textRangeProvider->Release(); + ComPtr textRangeProvider = + makeComObject(id(), startOffset, endOffset); + SafeArrayPutElement(*pRetVal, &i, textRangeProvider.Get()); } } } else { @@ -60,9 +60,9 @@ HRESULT STDMETHODCALLTYPE QWindowsUiaTextProvider::GetSelection(SAFEARRAY **pRet if ((*pRetVal = SafeArrayCreateVector(VT_UNKNOWN, 0, 1))) { LONG i = 0; int cursorPosition = textInterface->cursorPosition(); - auto *textRangeProvider = new QWindowsUiaTextRangeProvider(id(), cursorPosition, cursorPosition); - SafeArrayPutElement(*pRetVal, &i, static_cast(textRangeProvider)); - textRangeProvider->Release(); + ComPtr textRangeProvider = makeComObject( + id(), cursorPosition, cursorPosition); + SafeArrayPutElement(*pRetVal, &i, textRangeProvider.Get()); } } return S_OK; @@ -88,9 +88,9 @@ HRESULT STDMETHODCALLTYPE QWindowsUiaTextProvider::GetVisibleRanges(SAFEARRAY ** // Considering the entire text as visible. if ((*pRetVal = SafeArrayCreateVector(VT_UNKNOWN, 0, 1))) { LONG i = 0; - auto *textRangeProvider = new QWindowsUiaTextRangeProvider(id(), 0, textInterface->characterCount()); - SafeArrayPutElement(*pRetVal, &i, static_cast(textRangeProvider)); - textRangeProvider->Release(); + ComPtr textRangeProvider = + makeComObject(id(), 0, textInterface->characterCount()); + SafeArrayPutElement(*pRetVal, &i, textRangeProvider.Get()); } return S_OK; } @@ -135,7 +135,7 @@ HRESULT STDMETHODCALLTYPE QWindowsUiaTextProvider::RangeFromPoint(UiaPoint point if (offset < 0 || offset >= textInterface->characterCount()) return UIA_E_ELEMENTNOTAVAILABLE; - *pRetVal = new QWindowsUiaTextRangeProvider(id(), offset, offset); + *pRetVal = makeComObject(id(), offset, offset).Detach(); return S_OK; } @@ -156,7 +156,8 @@ HRESULT STDMETHODCALLTYPE QWindowsUiaTextProvider::get_DocumentRange(ITextRangeP if (!textInterface) return UIA_E_ELEMENTNOTAVAILABLE; - *pRetVal = new QWindowsUiaTextRangeProvider(id(), 0, textInterface->characterCount()); + *pRetVal = makeComObject(id(), 0, textInterface->characterCount()) + .Detach(); return S_OK; } @@ -202,7 +203,8 @@ HRESULT STDMETHODCALLTYPE QWindowsUiaTextProvider::GetCaretRange(BOOL *isActive, *isActive = accessible->state().focused; int cursorPosition = textInterface->cursorPosition(); - *pRetVal = new QWindowsUiaTextRangeProvider(id(), cursorPosition, cursorPosition); + *pRetVal = makeComObject(id(), cursorPosition, cursorPosition) + .Detach(); return S_OK; } diff --git a/src/plugins/platforms/windows/uiautomation/qwindowsuiatextrangeprovider.cpp b/src/plugins/platforms/windows/uiautomation/qwindowsuiatextrangeprovider.cpp index d837aac811c..a8d58e10105 100644 --- a/src/plugins/platforms/windows/uiautomation/qwindowsuiatextrangeprovider.cpp +++ b/src/plugins/platforms/windows/uiautomation/qwindowsuiatextrangeprovider.cpp @@ -45,7 +45,7 @@ HRESULT QWindowsUiaTextRangeProvider::Clone(ITextRangeProvider **pRetVal) if (!pRetVal) return E_INVALIDARG; - *pRetVal = new QWindowsUiaTextRangeProvider(id(), m_startOffset, m_endOffset); + *pRetVal = makeComObject(id(), m_startOffset, m_endOffset).Detach(); return S_OK; }