comparison dep/animone/src/a11y/win32.cc @ 341:052ec053ee37

dep/animone: a11y/win32: fix missing ComInterface definition
author Paper <paper@paper.us.eu.org>
date Wed, 19 Jun 2024 23:21:19 -0400
parents 74e2365326c6
children adb79bdde329
comparison
equal deleted inserted replaced
340:74e2365326c6 341:052ec053ee37
19 using ValuePattern = IUIAutomationValuePattern; 19 using ValuePattern = IUIAutomationValuePattern;
20 20
21 using element_proc_t = std::function<TreeScope(Element&)>; 21 using element_proc_t = std::function<TreeScope(Element&)>;
22 using properties_t = std::vector<std::pair<long, bool>>; 22 using properties_t = std::vector<std::pair<long, bool>>;
23 23
24 /* ------------------------------------------------------------------- */
25
26 template <typename T>
27 struct ComInterfaceDeleter {
28 static_assert(std::is_base_of<IUnknown, T>::value, "Invalid COM interface");
29 using pointer = T*;
30 void operator()(pointer p) const { if (p) p->Release(); }
31 };
32
33 template <typename T>
34 using ComInterface = std::unique_ptr<T, ComInterfaceDeleter<T>>;
35
36 /* ------------------------------------------------------------------- */
37
24 // The main interface that is used throughout this file. Must be initialized 38 // The main interface that is used throughout this file. Must be initialized
25 // before it can be used for the first time. 39 // before it can be used for the first time.
26 static ComInterface<IUIAutomation> ui_automation; 40 static ComInterface<IUIAutomation> ui_automation;
27 41
28 //////////////////////////////////////////////////////////////////////////////// 42 /* ------------------------------------------------------------------- */
29 43
30 static bool InitializeUIAutomation() { 44 static bool InitializeUIAutomation() {
31 if (ui_automation) 45 if (ui_automation)
32 return true; 46 return true;
33 47
42 ui_automation.reset(ui_automation_interface); 56 ui_automation.reset(ui_automation_interface);
43 57
44 return SUCCEEDED(result); 58 return SUCCEEDED(result);
45 } 59 }
46 60
47 //////////////////////////////////////////////////////////////////////////////// 61 /* ------------------------------------------------------------------- */
48 62
49 static Element* GetElementFromHandle(HWND hwnd) { 63 static Element* GetElementFromHandle(HWND hwnd) {
50 Element* element = nullptr; 64 Element* element = nullptr;
51 ui_automation->ElementFromHandle(static_cast<UIA_HWND>(hwnd), &element); 65 ui_automation->ElementFromHandle(static_cast<UIA_HWND>(hwnd), &element);
52 return element; 66 return element;
81 } 95 }
82 96
83 return element_value; 97 return element_value;
84 } 98 }
85 99
86 //////////////////////////////////////////////////////////////////////////////// 100 /* ------------------------------------------------------------------- */
87 101
88 static bool VerifyElementProperties(Element& element, const properties_t& properties) { 102 static bool VerifyElementProperties(Element& element, const properties_t& properties) {
89 VARIANT v = {}; 103 VARIANT v = {};
90 for (const auto& pair : properties) { 104 for (const auto& pair : properties) {
91 if (FAILED(element.GetCurrentPropertyValue(pair.first, &v))) 105 if (FAILED(element.GetCurrentPropertyValue(pair.first, &v)))
114 }; 128 };
115 129
116 return VerifyElementProperties(element, properties); 130 return VerifyElementProperties(element, properties);
117 } 131 }
118 132
119 //////////////////////////////////////////////////////////////////////////////// 133 /* ------------------------------------------------------------------- */
120 134
121 static void WalkElements(TreeWalker& tree_walker, Element& parent, TreeScope scope, 135 static void WalkElements(TreeWalker& tree_walker, Element& parent, TreeScope scope,
122 size_t depth, element_proc_t element_proc) { 136 size_t depth, element_proc_t element_proc) {
123 constexpr size_t kMaxTreeDepth = 16; // arbitrary value 137 constexpr size_t kMaxTreeDepth = 16; // arbitrary value
124 if (depth > kMaxTreeDepth) 138 if (depth > kMaxTreeDepth)