uiautomationcore: Put general purpose helper functions into separate source file.
[wine.git] / dlls / uiautomationcore / uia_private.h
blob5d3a64cb776d8e34ed08b60c73c1fc4aeb2c727e
1 /*
2 * Copyright 2022 Connor McAdams for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #define COBJMACROS
21 #include "uiautomation.h"
22 #include "uia_classes.h"
23 #include "wine/list.h"
24 #include "wine/heap.h"
26 extern HMODULE huia_module DECLSPEC_HIDDEN;
28 enum uia_prop_type {
29 PROP_TYPE_UNKNOWN,
30 PROP_TYPE_ELEM_PROP,
31 PROP_TYPE_SPECIAL,
32 PROP_TYPE_PATTERN_PROP,
36 * HUIANODEs that have an associated HWND are able to pull data from up to 4
37 * different providers:
39 * - Override providers are used to override values from all other providers.
40 * - Main providers are the base provider for an HUIANODE.
41 * - Nonclient providers are used to represent the nonclient area of the HWND.
42 * - HWND providers are used to represent data from the HWND as a whole, such
43 * as the bounding box.
45 * When a property is requested from the node, each provider is queried in
46 * descending order starting with the override provider until either one
47 * returns a property or there are no more providers to query.
49 enum uia_node_prov_type {
50 PROV_TYPE_OVERRIDE,
51 PROV_TYPE_MAIN,
52 PROV_TYPE_NONCLIENT,
53 PROV_TYPE_HWND,
54 PROV_TYPE_COUNT,
57 struct uia_node {
58 IWineUiaNode IWineUiaNode_iface;
59 LONG ref;
61 IWineUiaProvider *prov[PROV_TYPE_COUNT];
62 DWORD git_cookie[PROV_TYPE_COUNT];
63 int prov_count;
64 int parent_link_idx;
65 int creator_prov_idx;
67 HWND hwnd;
68 BOOL nested_node;
69 BOOL disconnected;
70 int creator_prov_type;
71 struct list prov_thread_list_entry;
72 struct list node_map_list_entry;
73 struct uia_provider_thread_map_entry *map;
76 static inline struct uia_node *impl_from_IWineUiaNode(IWineUiaNode *iface)
78 return CONTAINING_RECORD(iface, struct uia_node, IWineUiaNode_iface);
81 struct uia_provider {
82 IWineUiaProvider IWineUiaProvider_iface;
83 LONG ref;
85 IRawElementProviderSimple *elprov;
86 BOOL return_nested_node;
87 BOOL parent_check_ran;
88 BOOL has_parent;
91 static inline struct uia_provider *impl_from_IWineUiaProvider(IWineUiaProvider *iface)
93 return CONTAINING_RECORD(iface, struct uia_provider, IWineUiaProvider_iface);
96 struct uia_event
98 IWineUiaEvent IWineUiaEvent_iface;
99 LONG ref;
101 SAFEARRAY *runtime_id;
102 int event_id;
103 int scope;
105 IRawElementProviderAdviseEvents **event_advisers;
106 int event_advisers_count;
107 SIZE_T event_advisers_arr_size;
109 UiaEventCallback *cback;
112 static inline void variant_init_bool(VARIANT *v, BOOL val)
114 V_VT(v) = VT_BOOL;
115 V_BOOL(v) = val ? VARIANT_TRUE : VARIANT_FALSE;
118 static inline void variant_init_i4(VARIANT *v, int val)
120 V_VT(v) = VT_I4;
121 V_I4(v) = val;
124 static inline BOOL uia_array_reserve(void **elements, SIZE_T *capacity, SIZE_T count, SIZE_T size)
126 SIZE_T max_capacity, new_capacity;
127 void *new_elements;
129 if (count <= *capacity)
130 return TRUE;
132 max_capacity = ~(SIZE_T)0 / size;
133 if (count > max_capacity)
134 return FALSE;
136 new_capacity = max(1, *capacity);
137 while (new_capacity < count && new_capacity <= max_capacity / 2)
138 new_capacity *= 2;
139 if (new_capacity < count)
140 new_capacity = count;
142 if (!*elements)
143 new_elements = heap_alloc_zero(new_capacity * size);
144 else
145 new_elements = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, *elements, new_capacity * size);
146 if (!new_elements)
147 return FALSE;
149 *elements = new_elements;
150 *capacity = new_capacity;
151 return TRUE;
154 /* uia_client.c */
155 int get_node_provider_type_at_idx(struct uia_node *node, int idx) DECLSPEC_HIDDEN;
156 HRESULT attach_event_to_uia_node(HUIANODE node, struct uia_event *event) DECLSPEC_HIDDEN;
157 HRESULT create_uia_node_from_elprov(IRawElementProviderSimple *elprov, HUIANODE *out_node,
158 BOOL get_hwnd_providers) DECLSPEC_HIDDEN;
160 /* uia_com_client.c */
161 HRESULT create_uia_iface(IUnknown **iface, BOOL is_cui8) DECLSPEC_HIDDEN;
163 /* uia_event.c */
164 HRESULT uia_event_add_provider_event_adviser(IRawElementProviderAdviseEvents *advise_events,
165 struct uia_event *event) DECLSPEC_HIDDEN;
167 /* uia_ids.c */
168 const struct uia_prop_info *uia_prop_info_from_id(PROPERTYID prop_id) DECLSPEC_HIDDEN;
169 const struct uia_event_info *uia_event_info_from_id(EVENTID event_id) DECLSPEC_HIDDEN;
170 const struct uia_pattern_info *uia_pattern_info_from_id(PATTERNID pattern_id) DECLSPEC_HIDDEN;
171 const struct uia_control_type_info *uia_control_type_info_from_id(CONTROLTYPEID control_type_id) DECLSPEC_HIDDEN;
173 /* uia_provider.c */
174 HRESULT create_base_hwnd_provider(HWND hwnd, IRawElementProviderSimple **elprov) DECLSPEC_HIDDEN;
175 void uia_stop_provider_thread(void) DECLSPEC_HIDDEN;
176 void uia_provider_thread_remove_node(HUIANODE node) DECLSPEC_HIDDEN;
177 LRESULT uia_lresult_from_node(HUIANODE huianode) DECLSPEC_HIDDEN;
178 HRESULT create_msaa_provider(IAccessible *acc, long child_id, HWND hwnd, BOOL known_root_acc,
179 IRawElementProviderSimple **elprov) DECLSPEC_HIDDEN;
181 /* uia_utils.c */
182 HRESULT get_safearray_dim_bounds(SAFEARRAY *sa, UINT dim, LONG *lbound, LONG *elems) DECLSPEC_HIDDEN;
183 HRESULT get_safearray_bounds(SAFEARRAY *sa, LONG *lbound, LONG *elems) DECLSPEC_HIDDEN;
184 int uia_compare_safearrays(SAFEARRAY *sa1, SAFEARRAY *sa2, int prop_type) DECLSPEC_HIDDEN;