[PATCH 3/7] oleacc: Add get_name function for edit client accessible object.

Connor McAdams cmcadams at codeweavers.com
Wed Sep 22 11:20:52 CDT 2021


Signed-off-by: Connor McAdams <cmcadams at codeweavers.com>
---
 dlls/oleacc/client.c | 88 ++++++++++++++++++++++++++++++++++++++------
 1 file changed, 77 insertions(+), 11 deletions(-)

diff --git a/dlls/oleacc/client.c b/dlls/oleacc/client.c
index 043d98d93cc..ef6967752b4 100644
--- a/dlls/oleacc/client.c
+++ b/dlls/oleacc/client.c
@@ -20,6 +20,8 @@
 
 #include "oleacc_private.h"
 
+#include "commctrl.h"
+
 #include "wine/debug.h"
 #include "wine/heap.h"
 
@@ -27,6 +29,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(oleacc);
 
 typedef struct {
     HRESULT (*get_state)(IAccessible *, VARIANT, VARIANT *);
+    HRESULT (*get_name)(IAccessible *, VARIANT, BSTR *);
 } WinClassVtbl;
 
 typedef struct {
@@ -43,6 +46,25 @@ typedef struct {
     WinClassVtbl vtbl;
 } Client;
 
+static HRESULT acc_client_get_name_str(WCHAR *name, UINT len, BSTR *pszName)
+{
+    UINT i;
+
+    if(!len)
+        return S_FALSE;
+
+    for(i=0; i<len; i++) {
+        if(name[i] == '&') {
+            len--;
+            memmove(name+i, name+i+1, (len-i)*sizeof(WCHAR));
+            break;
+        }
+    }
+
+    *pszName = SysAllocStringLen(name, len);
+    return *pszName ? S_OK : E_OUTOFMEMORY;
+}
+
 static inline Client* impl_from_Client(IAccessible *iface)
 {
     return CONTAINING_RECORD(iface, Client, IAccessible_iface);
@@ -166,10 +188,13 @@ static HRESULT WINAPI Client_get_accName(IAccessible *iface, VARIANT varID, BSTR
 {
     Client *This = impl_from_Client(iface);
     WCHAR name[1024];
-    UINT i, len;
+    UINT len;
 
     TRACE("(%p)->(%s %p)\n", This, debugstr_variant(&varID), pszName);
 
+    if (This->vtbl.get_name)
+        return This->vtbl.get_name(iface, varID, pszName);
+
     *pszName = NULL;
     if(convert_child_id(&varID) != CHILDID_SELF || !IsWindow(This->hwnd))
         return E_INVALIDARG;
@@ -178,16 +203,7 @@ static HRESULT WINAPI Client_get_accName(IAccessible *iface, VARIANT varID, BSTR
     if(!len)
         return S_FALSE;
 
-    for(i=0; i<len; i++) {
-        if(name[i] == '&') {
-            len--;
-            memmove(name+i, name+i+1, (len-i)*sizeof(WCHAR));
-            break;
-        }
-    }
-
-    *pszName = SysAllocStringLen(name, len);
-    return *pszName ? S_OK : E_OUTOFMEMORY;
+    return acc_client_get_name_str(name, len, pszName);
 }
 
 static HRESULT WINAPI Client_get_accValue(IAccessible *iface, VARIANT varID, BSTR *pszValue)
@@ -693,6 +709,55 @@ HRESULT create_client_object(HWND hwnd, const IID *iid, void **obj)
     return hres;
 }
 
+/*
+ * Edit control objects have their name property defined by the first static
+ * text control preceding them in the order of window creation. If one is not
+ * found, the edit has no name property. In the case of the keyboard shortcut
+ * property, the first visible static text control is used.
+ */
+static HWND acc_edit_find_label(HWND hwnd, BOOL visible)
+{
+    HWND cur;
+
+    for(cur = hwnd; cur; cur = GetWindow(cur, GW_HWNDPREV)) {
+        WCHAR class_name[64];
+
+        if(!RealGetWindowClassW(cur, class_name, ARRAY_SIZE(class_name)))
+            continue;
+
+        if(!wcsicmp(class_name, WC_STATICW)) {
+            if (visible && !(GetWindowLongW(cur, GWL_STYLE) & WS_VISIBLE))
+                continue;
+            else
+                break;
+        }
+    }
+
+    return cur;
+}
+
+static HRESULT edit_get_name(IAccessible *iface, VARIANT var_id, BSTR *out_name)
+{
+    Client *This = impl_from_Client(iface);
+    WCHAR name[1024];
+    HWND label;
+    UINT len;
+
+    TRACE("(%p)->(%s %p)\n", This, debugstr_variant(&var_id), out_name);
+
+    *out_name = NULL;
+    if(convert_child_id(&var_id) != CHILDID_SELF || !IsWindow(This->hwnd))
+        return E_INVALIDARG;
+
+    label = acc_edit_find_label(This->hwnd, FALSE);
+    if(!label)
+        return S_FALSE;
+
+    len = SendMessageW(label, WM_GETTEXT, ARRAY_SIZE(name), (LPARAM)name);
+
+    return acc_client_get_name_str(name, len, out_name);
+}
+
 static HRESULT edit_get_state(IAccessible *iface, VARIANT var_id, VARIANT *out_state)
 {
     Client *This = impl_from_Client(iface);
@@ -728,6 +793,7 @@ HRESULT create_edit_client_object(HWND hwnd, const IID *iid, void **obj)
     client = impl_from_Client(acc);
     client->role = ROLE_SYSTEM_TEXT;
     client->vtbl.get_state = &edit_get_state;
+    client->vtbl.get_name = &edit_get_name;
 
     hres = IAccessible_QueryInterface(acc, iid, obj);
     IAccessible_Release(acc);
-- 
2.25.1




More information about the wine-devel mailing list