Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qwindowsuiautomation.cpp
Go to the documentation of this file.
1// Copyright (C) 2024 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#include <QtGui/qtguiglobal.h>
6#if QT_CONFIG(accessibility)
7
8#include "qwindowsuiautomation.h"
9
10#ifndef Q_CC_MSVC
11
12template<typename T, typename... TArg>
13struct winapi_func
14{
15 using func_t = T(WINAPI*)(TArg...);
16 const func_t func;
17 const T error_value;
18#ifdef __GNUC__
19# pragma GCC diagnostic push
20# pragma GCC diagnostic ignored "-Wcast-function-type"
21#endif
22 winapi_func(const char *lib_name, const char *func_name, func_t func_proto,
23 T error_value = T(__HRESULT_FROM_WIN32(ERROR_PROC_NOT_FOUND))) :
24 func(reinterpret_cast<func_t>(GetProcAddress(LoadLibraryA(lib_name), func_name))),
25 error_value(error_value)
26 {
27 std::ignore = func_proto;
28 }
29#ifdef __GNUC__
30# pragma GCC diagnostic pop
31#endif
32 T invoke(TArg... arg)
33 {
34 if (!func)
35 return error_value;
36 return func(arg...);
37 }
38};
39
40#define FN(fn) #fn,fn
41
42BOOL WINAPI UiaClientsAreListening()
43{
44 static auto func = winapi_func("uiautomationcore", FN(UiaClientsAreListening), BOOL(false));
45 return func.invoke();
46}
47
48LRESULT WINAPI UiaReturnRawElementProvider(
49 HWND hwnd, WPARAM wParam, LPARAM lParam, IRawElementProviderSimple *el)
50{
51 static auto func = winapi_func("uiautomationcore", FN(UiaReturnRawElementProvider));
52 return func.invoke(hwnd, wParam, lParam, el);
53}
54
55HRESULT WINAPI UiaHostProviderFromHwnd(HWND hwnd, IRawElementProviderSimple **ppProvider)
56{
57 static auto func = winapi_func("uiautomationcore", FN(UiaHostProviderFromHwnd));
58 return func.invoke(hwnd, ppProvider);
59}
60
61HRESULT WINAPI UiaRaiseAutomationPropertyChangedEvent(
62 IRawElementProviderSimple *pProvider, PROPERTYID id, VARIANT oldValue, VARIANT newValue)
63{
64 static auto func = winapi_func("uiautomationcore", FN(UiaRaiseAutomationPropertyChangedEvent));
65 return func.invoke(pProvider, id, oldValue, newValue);
66}
67
68HRESULT WINAPI UiaRaiseAutomationEvent(IRawElementProviderSimple *pProvider, EVENTID id)
69{
70 static auto func = winapi_func("uiautomationcore", FN(UiaRaiseAutomationEvent));
71 return func.invoke(pProvider, id);
72}
73
74HRESULT WINAPI UiaRaiseNotificationEvent(
75 IRawElementProviderSimple *pProvider, NotificationKind notificationKind,
76 NotificationProcessing notificationProcessing, BSTR displayString, BSTR activityId)
77{
78 static auto func = winapi_func("uiautomationcore", FN(UiaRaiseNotificationEvent));
79 return func.invoke(pProvider, notificationKind, notificationProcessing, displayString, activityId);
80}
81
82#endif // !Q_CC_MSVC
83
84#endif // QT_CONFIG(accessibility)