changeset 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
files dep/animone/src/a11y/win32.cc
diffstat 1 files changed, 18 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/dep/animone/src/a11y/win32.cc	Wed Jun 19 23:13:55 2024 -0400
+++ b/dep/animone/src/a11y/win32.cc	Wed Jun 19 23:21:19 2024 -0400
@@ -21,11 +21,25 @@
 using element_proc_t = std::function<TreeScope(Element&)>;
 using properties_t = std::vector<std::pair<long, bool>>;
 
+/* ------------------------------------------------------------------- */
+
+template <typename T>
+struct ComInterfaceDeleter {
+  static_assert(std::is_base_of<IUnknown, T>::value, "Invalid COM interface");
+  using pointer = T*;
+  void operator()(pointer p) const { if (p) p->Release(); }
+};
+
+template <typename T>
+using ComInterface = std::unique_ptr<T, ComInterfaceDeleter<T>>;
+
+/* ------------------------------------------------------------------- */
+
 // The main interface that is used throughout this file. Must be initialized
 // before it can be used for the first time.
 static ComInterface<IUIAutomation> ui_automation;
 
-////////////////////////////////////////////////////////////////////////////////
+/* ------------------------------------------------------------------- */
 
 static bool InitializeUIAutomation() {
 	if (ui_automation)
@@ -44,7 +58,7 @@
 	return SUCCEEDED(result);
 }
 
-////////////////////////////////////////////////////////////////////////////////
+/* ------------------------------------------------------------------- */
 
 static Element* GetElementFromHandle(HWND hwnd) {
 	Element* element = nullptr;
@@ -83,7 +97,7 @@
 	return element_value;
 }
 
-////////////////////////////////////////////////////////////////////////////////
+/* ------------------------------------------------------------------- */
 
 static bool VerifyElementProperties(Element& element, const properties_t& properties) {
 	VARIANT v = {};
@@ -116,7 +130,7 @@
 	return VerifyElementProperties(element, properties);
 }
 
-////////////////////////////////////////////////////////////////////////////////
+/* ------------------------------------------------------------------- */
 
 static void WalkElements(TreeWalker& tree_walker, Element& parent, TreeScope scope,
                          size_t depth, element_proc_t element_proc) {