Commit 3d0c9efc authored by Connor McAdams's avatar Connor McAdams Committed by Alexandre Julliard

uiautomationcore: Put general purpose helper functions into separate source file.

parent ad7b9726
......@@ -10,7 +10,8 @@ C_SRCS = \
uia_event.c \
uia_ids.c \
uia_main.c \
uia_provider.c
uia_provider.c \
uia_utils.c
IDL_SRCS = \
uia_classes.idl \
......
......@@ -58,93 +58,6 @@ static HRESULT add_node_to_node_array(struct uia_node_array *out_nodes, HUIANODE
return S_OK;
}
static HRESULT get_safearray_dim_bounds(SAFEARRAY *sa, UINT dim, LONG *lbound, LONG *elems)
{
LONG ubound;
HRESULT hr;
*lbound = *elems = 0;
hr = SafeArrayGetLBound(sa, dim, lbound);
if (FAILED(hr))
return hr;
hr = SafeArrayGetUBound(sa, dim, &ubound);
if (FAILED(hr))
return hr;
*elems = (ubound - (*lbound)) + 1;
return S_OK;
}
HRESULT get_safearray_bounds(SAFEARRAY *sa, LONG *lbound, LONG *elems)
{
UINT dims;
*lbound = *elems = 0;
dims = SafeArrayGetDim(sa);
if (dims != 1)
{
WARN("Invalid dimensions %d for safearray.\n", dims);
return E_FAIL;
}
return get_safearray_dim_bounds(sa, 1, lbound, elems);
}
int uia_compare_safearrays(SAFEARRAY *sa1, SAFEARRAY *sa2, int prop_type)
{
LONG i, idx, lbound[2], elems[2];
int val[2];
HRESULT hr;
hr = get_safearray_bounds(sa1, &lbound[0], &elems[0]);
if (FAILED(hr))
{
ERR("Failed to get safearray bounds from sa1 with hr %#lx\n", hr);
return -1;
}
hr = get_safearray_bounds(sa2, &lbound[1], &elems[1]);
if (FAILED(hr))
{
ERR("Failed to get safearray bounds from sa2 with hr %#lx\n", hr);
return -1;
}
if (elems[0] != elems[1])
return (elems[0] > elems[1]) - (elems[0] < elems[1]);
if (prop_type != UIAutomationType_IntArray)
{
FIXME("Array type %#x value comparison currently unimplemented.\n", prop_type);
return -1;
}
for (i = 0; i < elems[0]; i++)
{
idx = lbound[0] + i;
hr = SafeArrayGetElement(sa1, &idx, &val[0]);
if (FAILED(hr))
{
ERR("Failed to get element from sa1 with hr %#lx\n", hr);
return -1;
}
idx = lbound[1] + i;
hr = SafeArrayGetElement(sa2, &idx, &val[1]);
if (FAILED(hr))
{
ERR("Failed to get element from sa2 with hr %#lx\n", hr);
return -1;
}
if (val[0] != val[1])
return (val[0] > val[1]) - (val[0] < val[1]);
}
return 0;
}
static void clear_uia_node_ptr_safearray(SAFEARRAY *sa, LONG elems)
{
HUIANODE node;
......
......@@ -152,8 +152,6 @@ static inline BOOL uia_array_reserve(void **elements, SIZE_T *capacity, SIZE_T c
}
/* uia_client.c */
HRESULT get_safearray_bounds(SAFEARRAY *sa, LONG *lbound, LONG *elems) DECLSPEC_HIDDEN;
int uia_compare_safearrays(SAFEARRAY *sa1, SAFEARRAY *sa2, int prop_type) DECLSPEC_HIDDEN;
int get_node_provider_type_at_idx(struct uia_node *node, int idx) DECLSPEC_HIDDEN;
HRESULT attach_event_to_uia_node(HUIANODE node, struct uia_event *event) DECLSPEC_HIDDEN;
HRESULT create_uia_node_from_elprov(IRawElementProviderSimple *elprov, HUIANODE *out_node,
......@@ -179,3 +177,8 @@ void uia_provider_thread_remove_node(HUIANODE node) DECLSPEC_HIDDEN;
LRESULT uia_lresult_from_node(HUIANODE huianode) DECLSPEC_HIDDEN;
HRESULT create_msaa_provider(IAccessible *acc, long child_id, HWND hwnd, BOOL known_root_acc,
IRawElementProviderSimple **elprov) DECLSPEC_HIDDEN;
/* uia_utils.c */
HRESULT get_safearray_dim_bounds(SAFEARRAY *sa, UINT dim, LONG *lbound, LONG *elems) DECLSPEC_HIDDEN;
HRESULT get_safearray_bounds(SAFEARRAY *sa, LONG *lbound, LONG *elems) DECLSPEC_HIDDEN;
int uia_compare_safearrays(SAFEARRAY *sa1, SAFEARRAY *sa2, int prop_type) DECLSPEC_HIDDEN;
/*
* Copyright 2023 Connor McAdams for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "uia_private.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(uiautomation);
HRESULT get_safearray_dim_bounds(SAFEARRAY *sa, UINT dim, LONG *lbound, LONG *elems)
{
LONG ubound;
HRESULT hr;
*lbound = *elems = 0;
hr = SafeArrayGetLBound(sa, dim, lbound);
if (FAILED(hr))
return hr;
hr = SafeArrayGetUBound(sa, dim, &ubound);
if (FAILED(hr))
return hr;
*elems = (ubound - (*lbound)) + 1;
return S_OK;
}
HRESULT get_safearray_bounds(SAFEARRAY *sa, LONG *lbound, LONG *elems)
{
UINT dims;
*lbound = *elems = 0;
dims = SafeArrayGetDim(sa);
if (dims != 1)
{
WARN("Invalid dimensions %d for safearray.\n", dims);
return E_FAIL;
}
return get_safearray_dim_bounds(sa, 1, lbound, elems);
}
int uia_compare_safearrays(SAFEARRAY *sa1, SAFEARRAY *sa2, int prop_type)
{
LONG i, idx, lbound[2], elems[2];
int val[2];
HRESULT hr;
hr = get_safearray_bounds(sa1, &lbound[0], &elems[0]);
if (FAILED(hr))
{
ERR("Failed to get safearray bounds from sa1 with hr %#lx\n", hr);
return -1;
}
hr = get_safearray_bounds(sa2, &lbound[1], &elems[1]);
if (FAILED(hr))
{
ERR("Failed to get safearray bounds from sa2 with hr %#lx\n", hr);
return -1;
}
if (elems[0] != elems[1])
return (elems[0] > elems[1]) - (elems[0] < elems[1]);
if (prop_type != UIAutomationType_IntArray)
{
FIXME("Array type %#x value comparison currently unimplemented.\n", prop_type);
return -1;
}
for (i = 0; i < elems[0]; i++)
{
idx = lbound[0] + i;
hr = SafeArrayGetElement(sa1, &idx, &val[0]);
if (FAILED(hr))
{
ERR("Failed to get element from sa1 with hr %#lx\n", hr);
return -1;
}
idx = lbound[1] + i;
hr = SafeArrayGetElement(sa2, &idx, &val[1]);
if (FAILED(hr))
{
ERR("Failed to get element from sa2 with hr %#lx\n", hr);
return -1;
}
if (val[0] != val[1])
return (val[0] > val[1]) - (val[0] < val[1]);
}
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment