1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
|
// 24 december 2014
// TODOs:
// - make sure E_POINTER and RPC_E_DISCONNECTED are correct returns for IAccessible
// uncomment this to debug table linked list management
#define TABLE_DEBUG_LINKEDLIST
typedef struct tableAccWhat tableAccWhat;
struct tableAccWhat {
LONG role;
intptr_t row;
intptr_t column;
};
struct tableAcc {
const IAccessibleVtbl *vtbl;
ULONG refcount;
struct table *t;
IAccessible *std;
tableAccWhat what;
// the list of currently active accessibility objects is a doubly linked list
struct tableAcc *prev;
struct tableAcc *next;
};
#ifdef TABLE_DEBUG_LINKEDLIST
void list(struct table *t)
{
struct tableAcc *ta;
printf("\n");
if (t->firstAcc == NULL) {
printf("\tempty\n");
return;
}
printf("\t-> ");
for (ta = t->firstAcc; ta != NULL; ta = ta->next)
printf("%p ", ta);
printf("\n\t<- ");
for (ta = t->firstAcc; ta->next != NULL; ta = ta->next)
;
for (; ta != NULL; ta = ta->prev)
printf("%p ", ta);
printf("\n");
}
#endif
// called after each allocation
static struct tableAcc *newTableAcc(struct table *t, LONG role, intptr_t row, intptr_t column);
// common validation for accessibility functions that take varChild
// also normalizes what as if varChild == CHILDID_SELF
static HRESULT normalizeWhat(struct tableAcc *ta, VARIANT varChild, tableAccWhat *what)
{
LONG cid;
if (varChild.vt != VT_I4)
return E_INVALIDARG;
cid = varChild.lVal;
if (cid == CHILDID_SELF)
return S_OK;
cid--;
if (cid < 0)
return E_INVALIDARG;
switch (what->role) {
case ROLE_SYSTEM_TABLE:
// TODO +1?
if (cid >= ta->t->count)
return E_INVALIDARG;
what->role = ROLE_SYSTEM_ROW;
what->row = (intptr_t) cid;
what->column = -1;
break;
case ROLE_SYSTEM_ROW:
case ROLE_SYSTEM_CELL:
// TODO
break;
}
return S_OK;
}
#define TA ((struct tableAcc *) this)
static HRESULT STDMETHODCALLTYPE tableAccQueryInterface(IAccessible *this, REFIID riid, void **ppvObject)
{
if (ppvObject == NULL)
return E_POINTER;
if (IsEqualIID(riid, &IID_IUnknown) ||
IsEqualIID(riid, &IID_IDispatch) ||
IsEqualIID(riid, &IID_IAccessible)) {
IAccessible_AddRef(this);
*ppvObject = (void *) this;
return S_OK;
}
*ppvObject = NULL;
return E_NOINTERFACE;
}
// TODO use InterlockedIncrement()/InterlockedDecrement() for these?
static ULONG STDMETHODCALLTYPE tableAccAddRef(IAccessible *this)
{
TA->refcount++;
// TODO correct?
return TA->refcount;
}
static ULONG STDMETHODCALLTYPE tableAccRelease(IAccessible *this)
{
TA->refcount--;
if (TA->refcount == 0) {
struct tableAcc *prev, *next;
#ifdef TABLE_DEBUG_LINKEDLIST
if (TA->t != NULL) { printf("before delete:"); list(TA->t); }
#endif
if (TA->t != NULL && TA->t->firstAcc == TA)
TA->t->firstAcc = TA->next;
prev = TA->prev;
next = TA->next;
if (prev != NULL)
prev->next = next;
if (next != NULL)
next->prev = prev;
#ifdef TABLE_DEBUG_LINKEDLIST
if (TA->t != NULL) { printf("after delete:"); list(TA->t); }
#endif
if (TA->std != NULL)
IAccessible_Release(TA->std);
tableFree(TA, "error freeing Table accessibility object");
return 0;
}
return TA->refcount;
}
// IDispatch
// TODO make sure relegating these to the standard accessibility object is harmless
static HRESULT STDMETHODCALLTYPE tableAccGetTypeInfoCount(IAccessible *this, UINT *pctinfo)
{
if (TA->t == NULL || TA->std == NULL) {
// TODO set values on error
return RPC_E_DISCONNECTED;
}
return IAccessible_GetTypeInfoCount(TA->std, pctinfo);
}
static HRESULT STDMETHODCALLTYPE tableAccGetTypeInfo(IAccessible *this, UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
{
if (TA->t == NULL || TA->std == NULL) {
// TODO set values on error
return RPC_E_DISCONNECTED;
}
return IAccessible_GetTypeInfo(TA->std, iTInfo, lcid, ppTInfo);
}
static HRESULT STDMETHODCALLTYPE tableAccGetIDsOfNames(IAccessible *this, REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
{
if (TA->t == NULL || TA->std == NULL) {
// TODO set values on error
return RPC_E_DISCONNECTED;
}
return IAccessible_GetIDsOfNames(TA->std, riid, rgszNames, cNames, lcid, rgDispId);
}
static HRESULT STDMETHODCALLTYPE tableAccInvoke(IAccessible *this, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
if (TA->t == NULL || TA->std == NULL) {
// TODO set values on error
return RPC_E_DISCONNECTED;
}
return IAccessible_Invoke(TA->std, dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
}
// IAccessible
static HRESULT STDMETHODCALLTYPE tableAccget_accParent(IAccessible *this, IDispatch **ppdispParent)
{
if (TA->t == NULL || TA->std == NULL) {
// TODO set values on error
return RPC_E_DISCONNECTED;
}
return IAccessible_get_accParent(TA->std, ppdispParent);
}
static HRESULT STDMETHODCALLTYPE tableAccget_accChildCount(IAccessible *this, long *pcountChildren)
{
if (TA->t == NULL || TA->std == NULL) {
// TODO set values on error
return RPC_E_DISCONNECTED;
}
//TODO
if (pcountChildren == NULL)
return E_POINTER;
*pcountChildren = 0;
return S_OK;
return IAccessible_get_accChildCount(TA->std, pcountChildren);
}
static HRESULT STDMETHODCALLTYPE tableAccget_accChild(IAccessible *this, VARIANT varChild, IDispatch **ppdispChild)
{
if (TA->t == NULL || TA->std == NULL) {
// TODO set values on error
return RPC_E_DISCONNECTED;
}
return IAccessible_get_accChild(TA->std, varChild, ppdispChild);
}
static HRESULT STDMETHODCALLTYPE tableAccget_accName(IAccessible *this, VARIANT varChild, BSTR *pszName)
{
printf("get_accName() t %p std %p\n", TA->t, TA->std);
if (TA->t == NULL || TA->std == NULL) {
printf("returning RPC_E_DISCONNECTED\n");
// TODO set values on error
return RPC_E_DISCONNECTED;
}
printf("running main function\n");
//TODO
if (pszName == NULL)
return E_POINTER;
*pszName = SysAllocString(L"accessible table");
return S_OK;
return IAccessible_get_accName(TA->std, varChild, pszName);
}
static HRESULT STDMETHODCALLTYPE tableAccget_accValue(IAccessible *this, VARIANT varChild, BSTR *pszValue)
{
if (TA->t == NULL || TA->std == NULL) {
// TODO set values on error
return RPC_E_DISCONNECTED;
}
return IAccessible_get_accValue(TA->std, varChild, pszValue);
}
static HRESULT STDMETHODCALLTYPE tableAccget_accDescription(IAccessible *this, VARIANT varChild, BSTR *pszDescription)
{
if (TA->t == NULL || TA->std == NULL) {
// TODO set values on error
return RPC_E_DISCONNECTED;
}
return IAccessible_get_accDescription(TA->std, varChild, pszDescription);
}
static HRESULT STDMETHODCALLTYPE tableAccget_accRole(IAccessible *this, VARIANT varChild, VARIANT *pvarRole)
{
if (TA->t == NULL || TA->std == NULL) {
// TODO set values on error
return RPC_E_DISCONNECTED;
}
//TODO
if (pvarRole == NULL)
return E_POINTER;
pvarRole->vt = VT_I4;
pvarRole->lVal = TA->what.role;
return S_OK;
return IAccessible_get_accRole(TA->std, varChild, pvarRole);
}
static HRESULT STDMETHODCALLTYPE tableAccget_accState(IAccessible *this, VARIANT varChild, VARIANT *pvarState)
{
if (TA->t == NULL || TA->std == NULL) {
// TODO set values on error
return RPC_E_DISCONNECTED;
}
return IAccessible_get_accState(TA->std, varChild, pvarState);
}
static HRESULT STDMETHODCALLTYPE tableAccget_accHelp(IAccessible *this, VARIANT varChild, BSTR *pszHelp)
{
if (TA->t == NULL || TA->std == NULL) {
// TODO set values on error
return RPC_E_DISCONNECTED;
}
return IAccessible_get_accHelp(TA->std, varChild, pszHelp);
}
static HRESULT STDMETHODCALLTYPE tableAccget_accHelpTopic(IAccessible *this, BSTR *pszHelpFile, VARIANT varChild, long *pidTopic)
{
if (TA->t == NULL || TA->std == NULL) {
// TODO set values on error
return RPC_E_DISCONNECTED;
}
return IAccessible_get_accHelpTopic(TA->std, pszHelpFile, varChild, pidTopic);
}
static HRESULT STDMETHODCALLTYPE tableAccget_accKeyboardShortcut(IAccessible *this, VARIANT varChild, BSTR *pszKeyboardShortcut)
{
if (TA->t == NULL || TA->std == NULL) {
// TODO set values on error
return RPC_E_DISCONNECTED;
}
return IAccessible_get_accKeyboardShortcut(TA->std, varChild, pszKeyboardShortcut);
}
static HRESULT STDMETHODCALLTYPE tableAccget_accFocus(IAccessible *this, VARIANT *pvarChild)
{
if (TA->t == NULL || TA->std == NULL) {
// TODO set values on error
return RPC_E_DISCONNECTED;
}
return IAccessible_get_accFocus(TA->std, pvarChild);
}
static HRESULT STDMETHODCALLTYPE tableAccget_accSelection(IAccessible *this, VARIANT *pvarChildren)
{
if (TA->t == NULL || TA->std == NULL) {
// TODO set values on error
return RPC_E_DISCONNECTED;
}
return IAccessible_get_accSelection(TA->std, pvarChildren);
}
static HRESULT STDMETHODCALLTYPE tableAccget_accDefaultAction(IAccessible *this, VARIANT varChild, BSTR *pszDefaultAction)
{
if (TA->t == NULL || TA->std == NULL) {
// TODO set values on error
return RPC_E_DISCONNECTED;
}
return IAccessible_get_accDefaultAction(TA->std, varChild, pszDefaultAction);
}
static HRESULT STDMETHODCALLTYPE tableAccaccSelect(IAccessible *this, long flagsSelect, VARIANT varChild)
{
if (TA->t == NULL || TA->std == NULL) {
// TODO set values on error
return RPC_E_DISCONNECTED;
}
return IAccessible_accSelect(TA->std, flagsSelect, varChild);
}
static HRESULT STDMETHODCALLTYPE tableAccaccLocation(IAccessible *this, long *pxLeft, long *pyTop, long *pcxWidth, long *pcyHeight, VARIANT varChild)
{
if (TA->t == NULL || TA->std == NULL) {
// TODO set values on error
return RPC_E_DISCONNECTED;
}
return IAccessible_accLocation(TA->std, pxLeft, pyTop, pcxWidth, pcyHeight, varChild);
}
static HRESULT STDMETHODCALLTYPE tableAccaccNavigate(IAccessible *this, long navDir, VARIANT varStart, VARIANT *pvarEndUpAt)
{
if (TA->t == NULL || TA->std == NULL) {
// TODO set values on error
return RPC_E_DISCONNECTED;
}
return IAccessible_accNavigate(TA->std, navDir, varStart, pvarEndUpAt);
}
static HRESULT STDMETHODCALLTYPE tableAccaccHitTest(IAccessible *this, long xLeft, long yTop, VARIANT *pvarChild)
{
if (TA->t == NULL || TA->std == NULL) {
// TODO set values on error
return RPC_E_DISCONNECTED;
}
return IAccessible_accHitTest(TA->std, xLeft, yTop, pvarChild);
}
static HRESULT STDMETHODCALLTYPE tableAccaccDoDefaultAction(IAccessible *this, VARIANT varChild)
{
if (TA->t == NULL || TA->std == NULL) {
// TODO set values on error
return RPC_E_DISCONNECTED;
}
return IAccessible_accDoDefaultAction(TA->std, varChild);
}
static HRESULT STDMETHODCALLTYPE tableAccput_accName(IAccessible *this, VARIANT varChild, BSTR szName)
{
if (TA->t == NULL || TA->std == NULL) {
// TODO set values on error
return RPC_E_DISCONNECTED;
}
return IAccessible_put_accName(TA->std, varChild, szName);
}
static HRESULT STDMETHODCALLTYPE tableAccput_accValue(IAccessible *this, VARIANT varChild, BSTR szValue)
{
if (TA->t == NULL || TA->std == NULL) {
// TODO set values on error
return RPC_E_DISCONNECTED;
}
return IAccessible_put_accValue(TA->std, varChild, szValue);
}
static const IAccessibleVtbl tableAccVtbl = {
.QueryInterface = tableAccQueryInterface,
.AddRef = tableAccAddRef,
.Release = tableAccRelease,
.GetTypeInfoCount = tableAccGetTypeInfoCount,
.GetTypeInfo = tableAccGetTypeInfo,
.GetIDsOfNames = tableAccGetIDsOfNames,
.Invoke = tableAccInvoke,
.get_accParent = tableAccget_accParent,
.get_accChildCount = tableAccget_accChildCount,
.get_accChild = tableAccget_accChild,
.get_accName = tableAccget_accName,
.get_accValue = tableAccget_accValue,
.get_accDescription = tableAccget_accDescription,
.get_accRole = tableAccget_accRole,
.get_accState = tableAccget_accState,
.get_accHelp = tableAccget_accHelp,
.get_accHelpTopic = tableAccget_accHelpTopic,
.get_accKeyboardShortcut = tableAccget_accKeyboardShortcut,
.get_accFocus = tableAccget_accFocus,
.get_accSelection = tableAccget_accSelection,
.get_accDefaultAction = tableAccget_accDefaultAction,
.accSelect = tableAccaccSelect,
.accLocation = tableAccaccLocation,
.accNavigate = tableAccaccNavigate,
.accHitTest = tableAccaccHitTest,
.accDoDefaultAction = tableAccaccDoDefaultAction,
.put_accName = tableAccput_accName,
.put_accValue = tableAccput_accValue,
};
static struct tableAcc *newTableAcc(struct table *t, LONG role, intptr_t row, intptr_t column)
{
struct tableAcc *ta;
HRESULT hr;
IAccessible *std;
ta = (struct tableAcc *) tableAlloc(sizeof (struct tableAcc), "error creating Table accessibility object");
printf("new ta %p\n", ta);
ta->vtbl = &tableAccVtbl;
ta->refcount = 1;
ta->t = t;
// TODO adjust last argument
hr = CreateStdAccessibleObject(t->hwnd, OBJID_CLIENT, &IID_IAccessible, (void **) (&std));
if (hr != S_OK)
// TODO panichresult
panic("error creating standard accessible object for Table");
ta->std = std;
ta->what.role = role;
ta->what.row = row;
ta->what.column = column;
#ifdef TABLE_DEBUG_LINKEDLIST
printf("before add:"); list(t);
#endif
ta->next = t->firstAcc;
if (t->firstAcc != NULL)
t->firstAcc->prev = ta;
t->firstAcc = ta;
#ifdef TABLE_DEBUG_LINKEDLIST
printf("after add:"); list(t);
#endif
return ta;
}
static void invalidateTableAccs(struct table *t)
{
struct tableAcc *ta;
for (ta = t->firstAcc; ta != NULL; ta = ta->next) {
ta->t = NULL;
IAccessible_Release(ta->std);
ta->std = NULL;
}
t->firstAcc = NULL;
}
HANDLER(accessibilityHandler)
{
struct tableAcc *ta;
if (uMsg != WM_GETOBJECT)
return FALSE;
// OBJID_CLIENT evaluates to an expression of type LONG
// the documentation for WM_GETOBJECT says to cast "it" to a DWORD before comparing
// https://msdn.microsoft.com/en-us/library/windows/desktop/dd373624%28v=vs.85%29.aspx casts them both to DWORDs; let's do that
// its two siblings only cast lParam, resulting in an erroneous DWORD to LONG comparison
// The Old New Thing book does not cast anything
// Microsoft's MSAA sample casts lParam to LONG instead!
// (As you can probably tell, the biggest problem with MSAA is that its documentation is ambiguous and/or self-contradictory...)
if (((DWORD) lParam) != ((DWORD) OBJID_CLIENT))
return FALSE;
printf("creating ta\n");
ta = newTableAcc(t, ROLE_SYSTEM_TABLE, -1, -1);
printf("ta %p\n", ta);
*lResult = LresultFromObject(&IID_IAccessible, wParam, (LPUNKNOWN) (ta));
printf("lResult %I32d\n", *lResult);
// TODO check *lResult
return TRUE;
}
|