Module: wine Branch: master Commit: 3d0c9efc1eb113dc822ff61d5a6c4d6fa5523a0a URL: https://gitlab.winehq.org/wine/wine/-/commit/3d0c9efc1eb113dc822ff61d5a6c4d6...
Author: Connor McAdams cmcadams@codeweavers.com Date: Wed May 17 15:36:46 2023 -0400
uiautomationcore: Put general purpose helper functions into separate source file.
Signed-off-by: Connor McAdams cmcadams@codeweavers.com
---
dlls/uiautomationcore/Makefile.in | 3 +- dlls/uiautomationcore/uia_client.c | 87 ---------------------------- dlls/uiautomationcore/uia_private.h | 7 ++- dlls/uiautomationcore/uia_utils.c | 110 ++++++++++++++++++++++++++++++++++++ 4 files changed, 117 insertions(+), 90 deletions(-)
diff --git a/dlls/uiautomationcore/Makefile.in b/dlls/uiautomationcore/Makefile.in index 8156807c334..f0f2a853cfb 100644 --- a/dlls/uiautomationcore/Makefile.in +++ b/dlls/uiautomationcore/Makefile.in @@ -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 \ diff --git a/dlls/uiautomationcore/uia_client.c b/dlls/uiautomationcore/uia_client.c index 4a14fe8e48a..9ea66e27d61 100644 --- a/dlls/uiautomationcore/uia_client.c +++ b/dlls/uiautomationcore/uia_client.c @@ -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; diff --git a/dlls/uiautomationcore/uia_private.h b/dlls/uiautomationcore/uia_private.h index 9ee5c30aeef..5d3a64cb776 100644 --- a/dlls/uiautomationcore/uia_private.h +++ b/dlls/uiautomationcore/uia_private.h @@ -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; diff --git a/dlls/uiautomationcore/uia_utils.c b/dlls/uiautomationcore/uia_utils.c new file mode 100644 index 00000000000..67c01eed8c3 --- /dev/null +++ b/dlls/uiautomationcore/uia_utils.c @@ -0,0 +1,110 @@ +/* + * 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; +}