2 * Implementation of the OLEACC dll
4 * Copyright 2003 Mike McCormack for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 #include "oleacc_private.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(oleacc
);
38 static const WCHAR lresult_atom_prefix
[] = {'w','i','n','e','_','o','l','e','a','c','c',':'};
40 typedef HRESULT (WINAPI
*accessible_create
)(HWND
, const IID
*, void**);
42 extern HRESULT WINAPI
OLEACC_DllGetClassObject(REFCLSID
, REFIID
, void**) DECLSPEC_HIDDEN
;
43 extern BOOL WINAPI
OLEACC_DllMain(HINSTANCE
, DWORD
, void*) DECLSPEC_HIDDEN
;
44 extern HRESULT WINAPI
OLEACC_DllRegisterServer(void) DECLSPEC_HIDDEN
;
45 extern HRESULT WINAPI
OLEACC_DllUnregisterServer(void) DECLSPEC_HIDDEN
;
50 accessible_create create_client
;
51 accessible_create create_window
;
52 } builtin_classes
[] = {
53 {WC_LISTBOXW
, 0x10000, NULL
, NULL
},
54 {L
"#32768", 0x10001, NULL
, NULL
}, /* menu */
55 {WC_BUTTONW
, 0x10002, NULL
, NULL
},
56 {WC_STATICW
, 0x10003, NULL
, NULL
},
57 {WC_EDITW
, 0x10004, NULL
, NULL
},
58 {WC_COMBOBOXW
, 0x10005, NULL
, NULL
},
59 {L
"#32770", 0x10006, NULL
, NULL
}, /* dialog */
60 {L
"#32771", 0x10007, NULL
, NULL
}, /* winswitcher */
61 {L
"MDIClient", 0x10008, NULL
, NULL
},
62 {L
"#32769", 0x10009, NULL
, NULL
}, /* desktop */
63 {WC_SCROLLBARW
, 0x1000a, NULL
, NULL
},
64 {STATUSCLASSNAMEW
, 0x1000b, NULL
, NULL
},
65 {TOOLBARCLASSNAMEW
, 0x1000c, NULL
, NULL
},
66 {PROGRESS_CLASSW
, 0x1000d, NULL
, NULL
},
67 {ANIMATE_CLASSW
, 0x1000e, NULL
, NULL
},
68 {WC_TABCONTROLW
, 0x1000f, NULL
, NULL
},
69 {HOTKEY_CLASSW
, 0x10010, NULL
, NULL
},
70 {WC_HEADERW
, 0x10011, NULL
, NULL
},
71 {TRACKBAR_CLASSW
, 0x10012, NULL
, NULL
},
72 {WC_LISTVIEWW
, 0x10013, NULL
, NULL
},
73 {UPDOWN_CLASSW
, 0x10016, NULL
, NULL
},
74 {TOOLTIPS_CLASSW
, 0x10018, NULL
, NULL
},
75 {WC_TREEVIEWW
, 0x10019, NULL
, NULL
},
76 {MONTHCAL_CLASSW
, 0, NULL
, NULL
},
77 {DATETIMEPICK_CLASSW
, 0, NULL
, NULL
},
78 {WC_IPADDRESSW
, 0, NULL
, NULL
},
79 {L
"RICHEDIT", 0x1001c, NULL
, NULL
},
80 {L
"RichEdit20A", 0, NULL
, NULL
},
81 {L
"RichEdit20W", 0, NULL
, NULL
},
84 static HINSTANCE oleacc_handle
= 0;
86 int convert_child_id(VARIANT
*v
)
92 FIXME("unhandled child ID variant type: %d\n", V_VT(v
));
97 static accessible_create
get_builtin_accessible_obj(HWND hwnd
, LONG objid
)
102 if(!RealGetWindowClassW(hwnd
, class_name
, ARRAY_SIZE(class_name
)))
104 TRACE("got window class: %s\n", debugstr_w(class_name
));
106 for(i
=0; i
<ARRAY_SIZE(builtin_classes
); i
++) {
107 if(!wcsicmp(class_name
, builtin_classes
[i
].name
)) {
108 accessible_create ret
;
110 ret
= (objid
==OBJID_CLIENT
?
111 builtin_classes
[i
].create_client
:
112 builtin_classes
[i
].create_window
);
114 FIXME("unhandled window class: %s\n", debugstr_w(class_name
));
119 idx
= SendMessageW(hwnd
, WM_GETOBJECT
, 0, OBJID_QUERYCLASSNAMEIDX
);
121 for(i
=0; i
<ARRAY_SIZE(builtin_classes
); i
++) {
122 if(idx
== builtin_classes
[i
].idx
) {
123 accessible_create ret
;
125 ret
= (objid
==OBJID_CLIENT
?
126 builtin_classes
[i
].create_client
:
127 builtin_classes
[i
].create_window
);
129 FIXME("unhandled class name idx: %x\n", idx
);
134 WARN("unhandled class name idx: %x\n", idx
);
140 HRESULT WINAPI
CreateStdAccessibleObject( HWND hwnd
, LONG idObject
,
141 REFIID riidInterface
, void** ppvObject
)
143 accessible_create create
;
145 TRACE("%p %d %s %p\n", hwnd
, idObject
,
146 debugstr_guid( riidInterface
), ppvObject
);
150 create
= get_builtin_accessible_obj(hwnd
, idObject
);
151 if(create
) return create(hwnd
, riidInterface
, ppvObject
);
152 return create_client_object(hwnd
, riidInterface
, ppvObject
);
154 create
= get_builtin_accessible_obj(hwnd
, idObject
);
155 if(create
) return create(hwnd
, riidInterface
, ppvObject
);
156 return create_window_object(hwnd
, riidInterface
, ppvObject
);
158 FIXME("unhandled object id: %d\n", idObject
);
163 HRESULT WINAPI
ObjectFromLresult( LRESULT result
, REFIID riid
, WPARAM wParam
, void **ppObject
)
165 WCHAR atom_str
[ARRAY_SIZE(lresult_atom_prefix
)+3*8+3];
166 HANDLE server_proc
, server_mapping
, mapping
;
174 TRACE("%ld %s %ld %p\n", result
, debugstr_guid(riid
), wParam
, ppObject
);
177 FIXME("unsupported wParam = %lx\n", wParam
);
183 if(result
!= (ATOM
)result
)
186 if(!GlobalGetAtomNameW(result
, atom_str
, ARRAY_SIZE(atom_str
)))
188 if(memcmp(atom_str
, lresult_atom_prefix
, sizeof(lresult_atom_prefix
)))
190 p
= atom_str
+ ARRAY_SIZE(lresult_atom_prefix
);
191 proc_id
= wcstoul(p
, &p
, 16);
194 server_mapping
= ULongToHandle( wcstoul(p
+1, &p
, 16) );
197 size
= wcstoul(p
+1, &p
, 16);
201 server_proc
= OpenProcess(PROCESS_DUP_HANDLE
, FALSE
, proc_id
);
205 if(!DuplicateHandle(server_proc
, server_mapping
, GetCurrentProcess(), &mapping
,
206 0, FALSE
, DUPLICATE_CLOSE_SOURCE
|DUPLICATE_SAME_ACCESS
))
208 CloseHandle(server_proc
);
209 GlobalDeleteAtom(result
);
211 view
= MapViewOfFile(mapping
, FILE_MAP_READ
, 0, 0, 0);
212 CloseHandle(mapping
);
216 data
= GlobalAlloc(GMEM_FIXED
, size
);
218 UnmapViewOfFile(view
);
219 return E_OUTOFMEMORY
;
221 memcpy(data
, view
, size
);
222 UnmapViewOfFile(view
);
224 hr
= CreateStreamOnHGlobal(data
, TRUE
, &stream
);
230 hr
= CoUnmarshalInterface(stream
, riid
, ppObject
);
231 IStream_Release(stream
);
235 LRESULT WINAPI
LresultFromObject( REFIID riid
, WPARAM wParam
, LPUNKNOWN pAcc
)
237 static const LARGE_INTEGER seek_zero
= {{0}};
239 WCHAR atom_str
[ARRAY_SIZE(lresult_atom_prefix
)+3*8+3];
247 TRACE("%s %ld %p\n", debugstr_guid(riid
), wParam
, pAcc
);
250 FIXME("unsupported wParam = %lx\n", wParam
);
255 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &stream
);
259 hr
= CoMarshalInterface(stream
, riid
, pAcc
, MSHCTX_LOCAL
, NULL
, MSHLFLAGS_NORMAL
);
261 IStream_Release(stream
);
265 hr
= IStream_Seek(stream
, seek_zero
, STREAM_SEEK_SET
, NULL
);
267 IStream_Release(stream
);
271 hr
= IStream_Stat(stream
, &stat
, STATFLAG_NONAME
);
273 CoReleaseMarshalData(stream
);
274 IStream_Release(stream
);
276 }else if(stat
.cbSize
.u
.HighPart
) {
277 FIXME("stream size to big\n");
278 CoReleaseMarshalData(stream
);
279 IStream_Release(stream
);
283 mapping
= CreateFileMappingW(INVALID_HANDLE_VALUE
, NULL
, PAGE_READWRITE
,
284 stat
.cbSize
.u
.HighPart
, stat
.cbSize
.u
.LowPart
, NULL
);
286 CoReleaseMarshalData(stream
);
287 IStream_Release(stream
);
291 view
= MapViewOfFile(mapping
, FILE_MAP_WRITE
, 0, 0, 0);
293 CloseHandle(mapping
);
294 CoReleaseMarshalData(stream
);
295 IStream_Release(stream
);
299 hr
= IStream_Read(stream
, view
, stat
.cbSize
.u
.LowPart
, NULL
);
300 UnmapViewOfFile(view
);
302 CloseHandle(mapping
);
303 hr
= IStream_Seek(stream
, seek_zero
, STREAM_SEEK_SET
, NULL
);
305 CoReleaseMarshalData(stream
);
306 IStream_Release(stream
);
311 memcpy(atom_str
, lresult_atom_prefix
, sizeof(lresult_atom_prefix
));
312 swprintf(atom_str
+ARRAY_SIZE(lresult_atom_prefix
), 3*8 + 3, L
"%08x:%08x:%08x", GetCurrentProcessId(),
313 HandleToUlong(mapping
), stat
.cbSize
.u
.LowPart
);
314 atom
= GlobalAddAtomW(atom_str
);
316 CloseHandle(mapping
);
317 hr
= IStream_Seek(stream
, seek_zero
, STREAM_SEEK_SET
, NULL
);
319 CoReleaseMarshalData(stream
);
320 IStream_Release(stream
);
324 IStream_Release(stream
);
328 HRESULT WINAPI
AccessibleObjectFromPoint( POINT ptScreen
, IAccessible
** ppacc
, VARIANT
* pvarChild
)
330 FIXME("{%d,%d} %p %p: stub\n", ptScreen
.x
, ptScreen
.y
, ppacc
, pvarChild
);
334 HRESULT WINAPI
AccessibleObjectFromWindow( HWND hwnd
, DWORD dwObjectID
,
335 REFIID riid
, void** ppvObject
)
337 TRACE("%p %d %s %p\n", hwnd
, dwObjectID
,
338 debugstr_guid( riid
), ppvObject
);
347 lres
= SendMessageW(hwnd
, WM_GETOBJECT
, 0xffffffff, dwObjectID
);
351 return ObjectFromLresult(lres
, riid
, 0, ppvObject
);
354 return CreateStdAccessibleObject(hwnd
, dwObjectID
, riid
, ppvObject
);
357 HRESULT WINAPI
WindowFromAccessibleObject(IAccessible
*acc
, HWND
*phwnd
)
363 TRACE("%p %p\n", acc
, phwnd
);
365 IAccessible_AddRef(acc
);
367 hres
= IAccessible_QueryInterface(acc
, &IID_IOleWindow
, (void**)&ow
);
368 if(SUCCEEDED(hres
)) {
369 hres
= IOleWindow_GetWindow(ow
, phwnd
);
370 IOleWindow_Release(ow
);
371 IAccessible_Release(acc
);
375 hres
= IAccessible_get_accParent(acc
, &parent
);
376 IAccessible_Release(acc
);
379 if(hres
!=S_OK
|| !parent
) {
384 hres
= IDispatch_QueryInterface(parent
, &IID_IAccessible
, (void**)&acc
);
385 IDispatch_Release(parent
);
391 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
,
394 TRACE("%p, %d, %p\n", hinstDLL
, fdwReason
, lpvReserved
);
398 case DLL_PROCESS_ATTACH
:
399 oleacc_handle
= hinstDLL
;
400 DisableThreadLibraryCalls(hinstDLL
);
404 return OLEACC_DllMain(hinstDLL
, fdwReason
, lpvReserved
);
407 HRESULT WINAPI
DllRegisterServer(void)
409 return OLEACC_DllRegisterServer();
412 HRESULT WINAPI
DllUnregisterServer(void)
414 return OLEACC_DllUnregisterServer();
417 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID iid
, void **ppv
)
419 if(IsEqualGUID(&CLSID_CAccPropServices
, rclsid
)) {
420 TRACE("(CLSID_CAccPropServices %s %p)\n", debugstr_guid(iid
), ppv
);
421 return get_accpropservices_factory(iid
, ppv
);
424 if(IsEqualGUID(&CLSID_PSFactoryBuffer
, rclsid
)) {
425 TRACE("(CLSID_PSFactoryBuffer %s %p)\n", debugstr_guid(iid
), ppv
);
426 return OLEACC_DllGetClassObject(rclsid
, iid
, ppv
);
429 FIXME("%s %s %p: stub\n", debugstr_guid(rclsid
), debugstr_guid(iid
), ppv
);
433 void WINAPI
GetOleaccVersionInfo(DWORD
* pVersion
, DWORD
* pBuild
)
435 *pVersion
= MAKELONG(0,7); /* Windows 7 version of oleacc: 7.0.0.0 */
436 *pBuild
= MAKELONG(0,0);
439 HANDLE WINAPI
GetProcessHandleFromHwnd(HWND hwnd
)
445 if(!GetWindowThreadProcessId(hwnd
, &proc_id
))
447 return OpenProcess(PROCESS_DUP_HANDLE
| PROCESS_VM_OPERATION
|
448 PROCESS_VM_READ
| PROCESS_VM_WRITE
| SYNCHRONIZE
, TRUE
, proc_id
);
451 UINT WINAPI
GetRoleTextW(DWORD role
, LPWSTR lpRole
, UINT rolemax
)
456 TRACE("%u %p %u\n", role
, lpRole
, rolemax
);
458 /* return role text length */
460 return LoadStringW(oleacc_handle
, role
, (LPWSTR
)&resptr
, 0);
462 ret
= LoadStringW(oleacc_handle
, role
, lpRole
, rolemax
);
464 if(rolemax
> 0) lpRole
[0] = '\0';
471 UINT WINAPI
GetRoleTextA(DWORD role
, LPSTR lpRole
, UINT rolemax
)
476 TRACE("%u %p %u\n", role
, lpRole
, rolemax
);
478 if(lpRole
&& !rolemax
)
481 length
= GetRoleTextW(role
, NULL
, 0);
483 if(lpRole
&& rolemax
)
488 roletextW
= HeapAlloc(GetProcessHeap(), 0, (length
+ 1)*sizeof(WCHAR
));
492 GetRoleTextW(role
, roletextW
, length
+ 1);
494 length
= WideCharToMultiByte( CP_ACP
, 0, roletextW
, -1, NULL
, 0, NULL
, NULL
);
497 HeapFree(GetProcessHeap(), 0, roletextW
);
501 if(rolemax
< length
) {
502 HeapFree(GetProcessHeap(), 0, roletextW
);
507 WideCharToMultiByte( CP_ACP
, 0, roletextW
, -1, lpRole
, rolemax
, NULL
, NULL
);
509 if(rolemax
< length
){
510 lpRole
[rolemax
-1] = '\0';
514 HeapFree(GetProcessHeap(), 0, roletextW
);
519 UINT WINAPI
GetStateTextW(DWORD state_bit
, WCHAR
*state_str
, UINT state_str_len
)
523 TRACE("%x %p %u\n", state_bit
, state_str
, state_str_len
);
525 if(state_bit
& ~(STATE_SYSTEM_VALID
| STATE_SYSTEM_HASPOPUP
)) {
526 if(state_str
&& state_str_len
)
531 state_id
= IDS_STATE_NORMAL
;
538 UINT ret
= LoadStringW(oleacc_handle
, state_id
, state_str
, state_str_len
);
539 if(!ret
&& state_str_len
)
544 return LoadStringW(oleacc_handle
, state_id
, (WCHAR
*)&tmp
, 0);
549 UINT WINAPI
GetStateTextA(DWORD state_bit
, CHAR
*state_str
, UINT state_str_len
)
553 TRACE("%x %p %u\n", state_bit
, state_str
, state_str_len
);
555 if(state_str
&& !state_str_len
)
558 if(state_bit
& ~(STATE_SYSTEM_VALID
| STATE_SYSTEM_HASPOPUP
)) {
559 if(state_str
&& state_str_len
)
564 state_id
= IDS_STATE_NORMAL
;
571 UINT ret
= LoadStringA(oleacc_handle
, state_id
, state_str
, state_str_len
);
572 if(!ret
&& state_str_len
)
577 return LoadStringA(oleacc_handle
, state_id
, tmp
, sizeof(tmp
));
581 HRESULT WINAPI
AccessibleChildren(IAccessible
*container
,
582 LONG start
, LONG count
, VARIANT
*children
, LONG
*children_cnt
)
588 TRACE("%p %d %d %p %p\n", container
, start
, count
, children
, children_cnt
);
590 if(!container
|| !children
|| !children_cnt
)
593 for(i
=0; i
<count
; i
++)
594 VariantInit(children
+i
);
596 hr
= IAccessible_QueryInterface(container
, &IID_IEnumVARIANT
, (void**)&ev
);
598 hr
= IEnumVARIANT_Reset(ev
);
600 hr
= IEnumVARIANT_Skip(ev
, start
);
602 hr
= IEnumVARIANT_Next(ev
, count
, children
, (ULONG
*)children_cnt
);
603 IEnumVARIANT_Release(ev
);
607 hr
= IAccessible_get_accChildCount(container
, &child_no
);
611 for(i
=0; i
<count
&& start
+i
+1<=child_no
; i
++) {
614 V_VT(children
+i
) = VT_I4
;
615 V_I4(children
+i
) = start
+i
+1;
617 hr
= IAccessible_get_accChild(container
, children
[i
], &disp
);
618 if(SUCCEEDED(hr
) && disp
) {
619 V_VT(children
+i
) = VT_DISPATCH
;
620 V_DISPATCH(children
+i
) = disp
;
625 return i
==count
? S_OK
: S_FALSE
;