2 * Copyright 2014 Piotr Caban 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 #include "oleacc_private.h"
22 IAccessible IAccessible_iface
;
23 IOleWindow IOleWindow_iface
;
24 IEnumVARIANT IEnumVARIANT_iface
;
32 static inline Client
* impl_from_Client(IAccessible
*iface
)
34 return CONTAINING_RECORD(iface
, Client
, IAccessible_iface
);
37 static HRESULT WINAPI
Client_QueryInterface(IAccessible
*iface
, REFIID riid
, void **ppv
)
39 Client
*This
= impl_from_Client(iface
);
41 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
43 if(IsEqualIID(riid
, &IID_IAccessible
) ||
44 IsEqualIID(riid
, &IID_IDispatch
) ||
45 IsEqualIID(riid
, &IID_IUnknown
)) {
47 }else if(IsEqualIID(riid
, &IID_IOleWindow
)) {
48 *ppv
= &This
->IOleWindow_iface
;
49 }else if(IsEqualIID(riid
, &IID_IEnumVARIANT
)) {
50 *ppv
= &This
->IEnumVARIANT_iface
;
52 WARN("no interface: %s\n", debugstr_guid(riid
));
57 IAccessible_AddRef(iface
);
61 static ULONG WINAPI
Client_AddRef(IAccessible
*iface
)
63 Client
*This
= impl_from_Client(iface
);
64 ULONG ref
= InterlockedIncrement(&This
->ref
);
66 TRACE("(%p) ref = %u\n", This
, ref
);
70 static ULONG WINAPI
Client_Release(IAccessible
*iface
)
72 Client
*This
= impl_from_Client(iface
);
73 ULONG ref
= InterlockedDecrement(&This
->ref
);
75 TRACE("(%p) ref = %u\n", This
, ref
);
82 static HRESULT WINAPI
Client_GetTypeInfoCount(IAccessible
*iface
, UINT
*pctinfo
)
84 Client
*This
= impl_from_Client(iface
);
85 FIXME("(%p)->(%p)\n", This
, pctinfo
);
89 static HRESULT WINAPI
Client_GetTypeInfo(IAccessible
*iface
,
90 UINT iTInfo
, LCID lcid
, ITypeInfo
**ppTInfo
)
92 Client
*This
= impl_from_Client(iface
);
93 FIXME("(%p)->(%u %x %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
97 static HRESULT WINAPI
Client_GetIDsOfNames(IAccessible
*iface
, REFIID riid
,
98 LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
100 Client
*This
= impl_from_Client(iface
);
101 FIXME("(%p)->(%s %p %u %x %p)\n", This
, debugstr_guid(riid
),
102 rgszNames
, cNames
, lcid
, rgDispId
);
106 static HRESULT WINAPI
Client_Invoke(IAccessible
*iface
, DISPID dispIdMember
,
107 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
108 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
110 Client
*This
= impl_from_Client(iface
);
111 FIXME("(%p)->(%x %s %x %x %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
112 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
116 static HRESULT WINAPI
Client_get_accParent(IAccessible
*iface
, IDispatch
**ppdispParent
)
118 Client
*This
= impl_from_Client(iface
);
120 TRACE("(%p)->(%p)\n", This
, ppdispParent
);
122 return AccessibleObjectFromWindow(This
->hwnd
, OBJID_WINDOW
,
123 &IID_IDispatch
, (void**)ppdispParent
);
126 static HRESULT WINAPI
Client_get_accChildCount(IAccessible
*iface
, LONG
*pcountChildren
)
128 Client
*This
= impl_from_Client(iface
);
131 TRACE("(%p)->(%p)\n", This
, pcountChildren
);
134 for(cur
= GetWindow(This
->hwnd
, GW_CHILD
); cur
; cur
= GetWindow(cur
, GW_HWNDNEXT
))
140 static HRESULT WINAPI
Client_get_accChild(IAccessible
*iface
,
141 VARIANT varChildID
, IDispatch
**ppdispChild
)
143 Client
*This
= impl_from_Client(iface
);
145 TRACE("(%p)->(%s %p)\n", This
, debugstr_variant(&varChildID
), ppdispChild
);
151 static HRESULT WINAPI
Client_get_accName(IAccessible
*iface
, VARIANT varID
, BSTR
*pszName
)
153 Client
*This
= impl_from_Client(iface
);
157 TRACE("(%p)->(%s %p)\n", This
, debugstr_variant(&varID
), pszName
);
160 if(convert_child_id(&varID
) != CHILDID_SELF
|| !IsWindow(This
->hwnd
))
163 len
= SendMessageW(This
->hwnd
, WM_GETTEXT
, sizeof(name
)/sizeof(WCHAR
), (LPARAM
)name
);
167 for(i
=0; i
<len
; i
++) {
170 memmove(name
+i
, name
+i
+1, (len
-i
)*sizeof(WCHAR
));
175 *pszName
= SysAllocStringLen(name
, len
);
176 return *pszName
? S_OK
: E_OUTOFMEMORY
;
179 static HRESULT WINAPI
Client_get_accValue(IAccessible
*iface
, VARIANT varID
, BSTR
*pszValue
)
181 Client
*This
= impl_from_Client(iface
);
183 TRACE("(%p)->(%s %p)\n", This
, debugstr_variant(&varID
), pszValue
);
186 if(convert_child_id(&varID
) != CHILDID_SELF
)
191 static HRESULT WINAPI
Client_get_accDescription(IAccessible
*iface
,
192 VARIANT varID
, BSTR
*pszDescription
)
194 Client
*This
= impl_from_Client(iface
);
196 TRACE("(%p)->(%s %p)\n", This
, debugstr_variant(&varID
), pszDescription
);
198 *pszDescription
= NULL
;
199 if(convert_child_id(&varID
) != CHILDID_SELF
)
204 static HRESULT WINAPI
Client_get_accRole(IAccessible
*iface
, VARIANT varID
, VARIANT
*pvarRole
)
206 Client
*This
= impl_from_Client(iface
);
208 TRACE("(%p)->(%s %p)\n", This
, debugstr_variant(&varID
), pvarRole
);
210 if(convert_child_id(&varID
) != CHILDID_SELF
) {
211 V_VT(pvarRole
) = VT_EMPTY
;
215 V_VT(pvarRole
) = VT_I4
;
216 V_I4(pvarRole
) = ROLE_SYSTEM_CLIENT
;
220 static HRESULT WINAPI
Client_get_accState(IAccessible
*iface
, VARIANT varID
, VARIANT
*pvarState
)
222 Client
*This
= impl_from_Client(iface
);
225 TRACE("(%p)->(%s %p)\n", This
, debugstr_variant(&varID
), pvarState
);
227 if(convert_child_id(&varID
) != CHILDID_SELF
) {
228 V_VT(pvarState
) = VT_EMPTY
;
232 V_VT(pvarState
) = VT_I4
;
235 style
= GetWindowLongW(This
->hwnd
, GWL_STYLE
);
236 if(style
& WS_DISABLED
)
237 V_I4(pvarState
) |= STATE_SYSTEM_UNAVAILABLE
;
238 else if(IsWindow(This
->hwnd
))
239 V_I4(pvarState
) |= STATE_SYSTEM_FOCUSABLE
;
240 if(GetFocus() == This
->hwnd
)
241 V_I4(pvarState
) |= STATE_SYSTEM_FOCUSED
;
242 if(!(style
& WS_VISIBLE
))
243 V_I4(pvarState
) |= STATE_SYSTEM_INVISIBLE
;
247 static HRESULT WINAPI
Client_get_accHelp(IAccessible
*iface
, VARIANT varID
, BSTR
*pszHelp
)
249 Client
*This
= impl_from_Client(iface
);
251 TRACE("(%p)->(%s %p)\n", This
, debugstr_variant(&varID
), pszHelp
);
254 if(convert_child_id(&varID
) != CHILDID_SELF
)
259 static HRESULT WINAPI
Client_get_accHelpTopic(IAccessible
*iface
,
260 BSTR
*pszHelpFile
, VARIANT varID
, LONG
*pidTopic
)
262 Client
*This
= impl_from_Client(iface
);
263 FIXME("(%p)->(%p %s %p)\n", This
, pszHelpFile
, debugstr_variant(&varID
), pidTopic
);
267 static HRESULT WINAPI
Client_get_accKeyboardShortcut(IAccessible
*iface
,
268 VARIANT varID
, BSTR
*pszKeyboardShortcut
)
270 static const WCHAR shortcut_fmt
[] = {'A','l','t','+','!',0};
271 Client
*This
= impl_from_Client(iface
);
275 TRACE("(%p)->(%s %p)\n", This
, debugstr_variant(&varID
), pszKeyboardShortcut
);
277 *pszKeyboardShortcut
= NULL
;
278 if(convert_child_id(&varID
) != CHILDID_SELF
)
281 len
= SendMessageW(This
->hwnd
, WM_GETTEXT
, sizeof(name
)/sizeof(WCHAR
), (LPARAM
)name
);
282 for(i
=0; i
<len
; i
++) {
289 *pszKeyboardShortcut
= SysAllocString(shortcut_fmt
);
290 if(!*pszKeyboardShortcut
)
291 return E_OUTOFMEMORY
;
293 (*pszKeyboardShortcut
)[4] = name
[i
+1];
297 static HRESULT WINAPI
Client_get_accFocus(IAccessible
*iface
, VARIANT
*pvarID
)
299 Client
*This
= impl_from_Client(iface
);
300 FIXME("(%p)->(%p)\n", This
, pvarID
);
304 static HRESULT WINAPI
Client_get_accSelection(IAccessible
*iface
, VARIANT
*pvarID
)
306 Client
*This
= impl_from_Client(iface
);
307 FIXME("(%p)->(%p)\n", This
, pvarID
);
311 static HRESULT WINAPI
Client_get_accDefaultAction(IAccessible
*iface
,
312 VARIANT varID
, BSTR
*pszDefaultAction
)
314 Client
*This
= impl_from_Client(iface
);
316 TRACE("(%p)->(%s %p)\n", This
, debugstr_variant(&varID
), pszDefaultAction
);
318 *pszDefaultAction
= NULL
;
319 if(convert_child_id(&varID
) != CHILDID_SELF
)
324 static HRESULT WINAPI
Client_accSelect(IAccessible
*iface
, LONG flagsSelect
, VARIANT varID
)
326 Client
*This
= impl_from_Client(iface
);
327 FIXME("(%p)->(%x %s)\n", This
, flagsSelect
, debugstr_variant(&varID
));
331 static HRESULT WINAPI
Client_accLocation(IAccessible
*iface
, LONG
*pxLeft
,
332 LONG
*pyTop
, LONG
*pcxWidth
, LONG
*pcyHeight
, VARIANT varID
)
334 Client
*This
= impl_from_Client(iface
);
338 TRACE("(%p)->(%p %p %p %p %s)\n", This
, pxLeft
, pyTop
,
339 pcxWidth
, pcyHeight
, debugstr_variant(&varID
));
341 *pxLeft
= *pyTop
= *pcxWidth
= *pcyHeight
= 0;
342 if(convert_child_id(&varID
) != CHILDID_SELF
)
345 if(!GetClientRect(This
->hwnd
, &rect
))
350 MapWindowPoints(This
->hwnd
, NULL
, &pt
, 1);
356 MapWindowPoints(This
->hwnd
, NULL
, &pt
, 1);
357 *pcxWidth
= pt
.x
- *pxLeft
;
358 *pcyHeight
= pt
.y
- *pyTop
;
362 static HRESULT WINAPI
Client_accNavigate(IAccessible
*iface
,
363 LONG navDir
, VARIANT varStart
, VARIANT
*pvarEnd
)
365 Client
*This
= impl_from_Client(iface
);
366 FIXME("(%p)->(%d %s %p)\n", This
, navDir
, debugstr_variant(&varStart
), pvarEnd
);
370 static HRESULT WINAPI
Client_accHitTest(IAccessible
*iface
,
371 LONG xLeft
, LONG yTop
, VARIANT
*pvarID
)
373 Client
*This
= impl_from_Client(iface
);
377 TRACE("(%p)->(%d %d %p)\n", This
, xLeft
, yTop
, pvarID
);
379 V_VT(pvarID
) = VT_I4
;
384 if(!IsWindowVisible(This
->hwnd
) || !ScreenToClient(This
->hwnd
, &pt
))
387 child
= ChildWindowFromPointEx(This
->hwnd
, pt
, CWP_SKIPINVISIBLE
);
388 if(!child
|| child
==This
->hwnd
)
391 V_VT(pvarID
) = VT_DISPATCH
;
392 return AccessibleObjectFromWindow(child
, OBJID_WINDOW
,
393 &IID_IDispatch
, (void**)&V_DISPATCH(pvarID
));
396 static HRESULT WINAPI
Client_accDoDefaultAction(IAccessible
*iface
, VARIANT varID
)
398 Client
*This
= impl_from_Client(iface
);
399 FIXME("(%p)->(%s)\n", This
, debugstr_variant(&varID
));
403 static HRESULT WINAPI
Client_put_accName(IAccessible
*iface
, VARIANT varID
, BSTR pszName
)
405 Client
*This
= impl_from_Client(iface
);
406 FIXME("(%p)->(%s %s)\n", This
, debugstr_variant(&varID
), debugstr_w(pszName
));
410 static HRESULT WINAPI
Client_put_accValue(IAccessible
*iface
, VARIANT varID
, BSTR pszValue
)
412 Client
*This
= impl_from_Client(iface
);
413 FIXME("(%p)->(%s %s)\n", This
, debugstr_variant(&varID
), debugstr_w(pszValue
));
417 static const IAccessibleVtbl ClientVtbl
= {
418 Client_QueryInterface
,
421 Client_GetTypeInfoCount
,
423 Client_GetIDsOfNames
,
425 Client_get_accParent
,
426 Client_get_accChildCount
,
430 Client_get_accDescription
,
434 Client_get_accHelpTopic
,
435 Client_get_accKeyboardShortcut
,
437 Client_get_accSelection
,
438 Client_get_accDefaultAction
,
443 Client_accDoDefaultAction
,
448 static inline Client
* impl_from_Client_OleWindow(IOleWindow
*iface
)
450 return CONTAINING_RECORD(iface
, Client
, IOleWindow_iface
);
453 static HRESULT WINAPI
Client_OleWindow_QueryInterface(IOleWindow
*iface
, REFIID riid
, void **ppv
)
455 Client
*This
= impl_from_Client_OleWindow(iface
);
456 return IAccessible_QueryInterface(&This
->IAccessible_iface
, riid
, ppv
);
459 static ULONG WINAPI
Client_OleWindow_AddRef(IOleWindow
*iface
)
461 Client
*This
= impl_from_Client_OleWindow(iface
);
462 return IAccessible_AddRef(&This
->IAccessible_iface
);
465 static ULONG WINAPI
Client_OleWindow_Release(IOleWindow
*iface
)
467 Client
*This
= impl_from_Client_OleWindow(iface
);
468 return IAccessible_Release(&This
->IAccessible_iface
);
471 static HRESULT WINAPI
Client_OleWindow_GetWindow(IOleWindow
*iface
, HWND
*phwnd
)
473 Client
*This
= impl_from_Client_OleWindow(iface
);
475 TRACE("(%p)->(%p)\n", This
, phwnd
);
481 static HRESULT WINAPI
Client_OleWindow_ContextSensitiveHelp(IOleWindow
*iface
, BOOL fEnterMode
)
483 Client
*This
= impl_from_Client_OleWindow(iface
);
484 FIXME("(%p)->(%x)\n", This
, fEnterMode
);
488 static const IOleWindowVtbl ClientOleWindowVtbl
= {
489 Client_OleWindow_QueryInterface
,
490 Client_OleWindow_AddRef
,
491 Client_OleWindow_Release
,
492 Client_OleWindow_GetWindow
,
493 Client_OleWindow_ContextSensitiveHelp
496 static inline Client
* impl_from_Client_EnumVARIANT(IEnumVARIANT
*iface
)
498 return CONTAINING_RECORD(iface
, Client
, IEnumVARIANT_iface
);
501 static HRESULT WINAPI
Client_EnumVARIANT_QueryInterface(IEnumVARIANT
*iface
, REFIID riid
, void **ppv
)
503 Client
*This
= impl_from_Client_EnumVARIANT(iface
);
504 return IAccessible_QueryInterface(&This
->IAccessible_iface
, riid
, ppv
);
507 static ULONG WINAPI
Client_EnumVARIANT_AddRef(IEnumVARIANT
*iface
)
509 Client
*This
= impl_from_Client_EnumVARIANT(iface
);
510 return IAccessible_AddRef(&This
->IAccessible_iface
);
513 static ULONG WINAPI
Client_EnumVARIANT_Release(IEnumVARIANT
*iface
)
515 Client
*This
= impl_from_Client_EnumVARIANT(iface
);
516 return IAccessible_Release(&This
->IAccessible_iface
);
519 static HRESULT WINAPI
Client_EnumVARIANT_Next(IEnumVARIANT
*iface
,
520 ULONG celt
, VARIANT
*rgVar
, ULONG
*pCeltFetched
)
522 Client
*This
= impl_from_Client_EnumVARIANT(iface
);
523 HWND cur
= This
->enum_pos
, next
;
527 TRACE("(%p)->(%u %p %p)\n", This
, celt
, rgVar
, pCeltFetched
);
536 next
= GetWindow(This
->hwnd
, GW_CHILD
);
538 next
= GetWindow(This
->enum_pos
, GW_HWNDNEXT
);
543 V_VT(rgVar
+fetched
) = VT_DISPATCH
;
544 hr
= AccessibleObjectFromWindow(cur
, OBJID_WINDOW
,
545 &IID_IDispatch
, (void**)&V_DISPATCH(rgVar
+fetched
));
547 V_VT(rgVar
+fetched
) = VT_EMPTY
;
549 VariantClear(rgVar
+fetched
-1);
560 next
= GetWindow(cur
, GW_HWNDNEXT
);
563 This
->enum_pos
= cur
;
565 *pCeltFetched
= fetched
;
566 return celt
== fetched
? S_OK
: S_FALSE
;
569 static HRESULT WINAPI
Client_EnumVARIANT_Skip(IEnumVARIANT
*iface
, ULONG celt
)
571 Client
*This
= impl_from_Client_EnumVARIANT(iface
);
574 TRACE("(%p)->(%u)\n", This
, celt
);
578 next
= GetWindow(This
->hwnd
, GW_CHILD
);
580 next
= GetWindow(This
->enum_pos
, GW_HWNDNEXT
);
584 This
->enum_pos
= next
;
591 static HRESULT WINAPI
Client_EnumVARIANT_Reset(IEnumVARIANT
*iface
)
593 Client
*This
= impl_from_Client_EnumVARIANT(iface
);
595 TRACE("(%p)\n", This
);
601 static HRESULT WINAPI
Client_EnumVARIANT_Clone(IEnumVARIANT
*iface
, IEnumVARIANT
**ppEnum
)
603 Client
*This
= impl_from_Client_EnumVARIANT(iface
);
604 FIXME("(%p)->(%p)\n", This
, ppEnum
);
608 static const IEnumVARIANTVtbl ClientEnumVARIANTVtbl
= {
609 Client_EnumVARIANT_QueryInterface
,
610 Client_EnumVARIANT_AddRef
,
611 Client_EnumVARIANT_Release
,
612 Client_EnumVARIANT_Next
,
613 Client_EnumVARIANT_Skip
,
614 Client_EnumVARIANT_Reset
,
615 Client_EnumVARIANT_Clone
618 HRESULT
create_client_object(HWND hwnd
, const IID
*iid
, void **obj
)
626 client
= heap_alloc_zero(sizeof(Client
));
628 return E_OUTOFMEMORY
;
630 client
->IAccessible_iface
.lpVtbl
= &ClientVtbl
;
631 client
->IOleWindow_iface
.lpVtbl
= &ClientOleWindowVtbl
;
632 client
->IEnumVARIANT_iface
.lpVtbl
= &ClientEnumVARIANTVtbl
;
635 client
->enum_pos
= 0;
637 hres
= IAccessible_QueryInterface(&client
->IAccessible_iface
, iid
, obj
);
638 IAccessible_Release(&client
->IAccessible_iface
);