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/unicode.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(oleacc
);
39 static const WCHAR lresult_atom_prefix
[] = {'w','i','n','e','_','o','l','e','a','c','c',':'};
41 static const WCHAR menuW
[] = {'#','3','2','7','6','8',0};
42 static const WCHAR desktopW
[] = {'#','3','2','7','6','9',0};
43 static const WCHAR dialogW
[] = {'#','3','2','7','7','0',0};
44 static const WCHAR winswitchW
[] = {'#','3','2','7','7','1',0};
45 static const WCHAR mdi_clientW
[] = {'M','D','I','C','l','i','e','n','t',0};
46 static const WCHAR richeditW
[] = {'R','I','C','H','E','D','I','T',0};
47 static const WCHAR richedit20aW
[] = {'R','i','c','h','E','d','i','t','2','0','A',0};
48 static const WCHAR richedit20wW
[] = {'R','i','c','h','E','d','i','t','2','0','W',0};
50 typedef HRESULT (WINAPI
*accessible_create
)(HWND
, const IID
*, void**);
55 accessible_create create_client
;
56 accessible_create create_window
;
57 } builtin_classes
[] = {
58 {WC_LISTBOXW
, 0x10000, NULL
, NULL
},
59 {menuW
, 0x10001, NULL
, NULL
},
60 {WC_BUTTONW
, 0x10002, NULL
, NULL
},
61 {WC_STATICW
, 0x10003, NULL
, NULL
},
62 {WC_EDITW
, 0x10004, NULL
, NULL
},
63 {WC_COMBOBOXW
, 0x10005, NULL
, NULL
},
64 {dialogW
, 0x10006, NULL
, NULL
},
65 {winswitchW
, 0x10007, NULL
, NULL
},
66 {mdi_clientW
, 0x10008, NULL
, NULL
},
67 {desktopW
, 0x10009, NULL
, NULL
},
68 {WC_SCROLLBARW
, 0x1000a, NULL
, NULL
},
69 {STATUSCLASSNAMEW
, 0x1000b, NULL
, NULL
},
70 {TOOLBARCLASSNAMEW
, 0x1000c, NULL
, NULL
},
71 {PROGRESS_CLASSW
, 0x1000d, NULL
, NULL
},
72 {ANIMATE_CLASSW
, 0x1000e, NULL
, NULL
},
73 {WC_TABCONTROLW
, 0x1000f, NULL
, NULL
},
74 {HOTKEY_CLASSW
, 0x10010, NULL
, NULL
},
75 {WC_HEADERW
, 0x10011, NULL
, NULL
},
76 {TRACKBAR_CLASSW
, 0x10012, NULL
, NULL
},
77 {WC_LISTVIEWW
, 0x10013, NULL
, NULL
},
78 {UPDOWN_CLASSW
, 0x10016, NULL
, NULL
},
79 {TOOLTIPS_CLASSW
, 0x10018, NULL
, NULL
},
80 {WC_TREEVIEWW
, 0x10019, NULL
, NULL
},
81 {MONTHCAL_CLASSW
, 0, NULL
, NULL
},
82 {DATETIMEPICK_CLASSW
, 0, NULL
, NULL
},
83 {WC_IPADDRESSW
, 0, NULL
, NULL
},
84 {richeditW
, 0x1001c, NULL
, NULL
},
85 {richedit20aW
, 0, NULL
, NULL
},
86 {richedit20wW
, 0, NULL
, NULL
},
89 static HINSTANCE oleacc_handle
= 0;
91 int convert_child_id(VARIANT
*v
)
97 FIXME("unhandled child ID variant type: %d\n", V_VT(v
));
102 static accessible_create
get_builtin_accessible_obj(HWND hwnd
, LONG objid
)
104 WCHAR class_name
[64];
107 if(!RealGetWindowClassW(hwnd
, class_name
, sizeof(class_name
)/sizeof(WCHAR
)))
109 TRACE("got window class: %s\n", debugstr_w(class_name
));
111 for(i
=0; i
<sizeof(builtin_classes
)/sizeof(builtin_classes
[0]); i
++) {
112 if(!strcmpiW(class_name
, builtin_classes
[i
].name
)) {
113 accessible_create ret
;
115 ret
= (objid
==OBJID_CLIENT
?
116 builtin_classes
[i
].create_client
:
117 builtin_classes
[i
].create_window
);
119 FIXME("unhandled window class: %s\n", debugstr_w(class_name
));
124 idx
= SendMessageW(hwnd
, WM_GETOBJECT
, 0, OBJID_QUERYCLASSNAMEIDX
);
126 for(i
=0; i
<sizeof(builtin_classes
)/sizeof(builtin_classes
[0]); i
++) {
127 if(idx
== builtin_classes
[i
].idx
) {
128 accessible_create ret
;
130 ret
= (objid
==OBJID_CLIENT
?
131 builtin_classes
[i
].create_client
:
132 builtin_classes
[i
].create_window
);
134 FIXME("unhandled class name idx: %x\n", idx
);
139 WARN("unhandled class name idx: %x\n", idx
);
145 HRESULT WINAPI
CreateStdAccessibleObject( HWND hwnd
, LONG idObject
,
146 REFIID riidInterface
, void** ppvObject
)
148 accessible_create create
;
150 TRACE("%p %d %s %p\n", hwnd
, idObject
,
151 debugstr_guid( riidInterface
), ppvObject
);
155 create
= get_builtin_accessible_obj(hwnd
, idObject
);
156 if(create
) return create(hwnd
, riidInterface
, ppvObject
);
157 return create_client_object(hwnd
, riidInterface
, ppvObject
);
159 create
= get_builtin_accessible_obj(hwnd
, idObject
);
160 if(create
) return create(hwnd
, riidInterface
, ppvObject
);
161 return create_window_object(hwnd
, riidInterface
, ppvObject
);
163 FIXME("unhandled object id: %d\n", idObject
);
168 HRESULT WINAPI
ObjectFromLresult( LRESULT result
, REFIID riid
, WPARAM wParam
, void **ppObject
)
170 WCHAR atom_str
[sizeof(lresult_atom_prefix
)/sizeof(WCHAR
)+3*8+3];
171 HANDLE server_proc
, server_mapping
, mapping
;
179 TRACE("%ld %s %ld %p\n", result
, debugstr_guid(riid
), wParam
, ppObject
);
182 FIXME("unsupported wParam = %lx\n", wParam
);
188 if(result
!= (ATOM
)result
)
191 if(!GlobalGetAtomNameW(result
, atom_str
, sizeof(atom_str
)/sizeof(WCHAR
)))
193 if(memcmp(atom_str
, lresult_atom_prefix
, sizeof(lresult_atom_prefix
)))
195 p
= atom_str
+ sizeof(lresult_atom_prefix
)/sizeof(WCHAR
);
196 proc_id
= strtoulW(p
, &p
, 16);
199 server_mapping
= ULongToHandle( strtoulW(p
+1, &p
, 16) );
202 size
= strtoulW(p
+1, &p
, 16);
206 server_proc
= OpenProcess(PROCESS_DUP_HANDLE
, FALSE
, proc_id
);
210 if(!DuplicateHandle(server_proc
, server_mapping
, GetCurrentProcess(), &mapping
,
211 0, FALSE
, DUPLICATE_CLOSE_SOURCE
|DUPLICATE_SAME_ACCESS
))
213 CloseHandle(server_proc
);
214 GlobalDeleteAtom(result
);
216 view
= MapViewOfFile(mapping
, FILE_MAP_READ
, 0, 0, 0);
217 CloseHandle(mapping
);
221 data
= GlobalAlloc(GMEM_FIXED
, size
);
223 UnmapViewOfFile(view
);
224 return E_OUTOFMEMORY
;
226 memcpy(data
, view
, size
);
227 UnmapViewOfFile(view
);
229 hr
= CreateStreamOnHGlobal(data
, TRUE
, &stream
);
235 hr
= CoUnmarshalInterface(stream
, riid
, ppObject
);
236 IStream_Release(stream
);
240 LRESULT WINAPI
LresultFromObject( REFIID riid
, WPARAM wParam
, LPUNKNOWN pAcc
)
242 static const WCHAR atom_fmt
[] = {'%','0','8','x',':','%','0','8','x',':','%','0','8','x',0};
243 static const LARGE_INTEGER seek_zero
= {{0}};
245 WCHAR atom_str
[sizeof(lresult_atom_prefix
)/sizeof(WCHAR
)+3*8+3];
253 TRACE("%s %ld %p\n", debugstr_guid(riid
), wParam
, pAcc
);
256 FIXME("unsupported wParam = %lx\n", wParam
);
261 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &stream
);
265 hr
= CoMarshalInterface(stream
, riid
, pAcc
, MSHCTX_LOCAL
, NULL
, MSHLFLAGS_NORMAL
);
267 IStream_Release(stream
);
271 hr
= IStream_Seek(stream
, seek_zero
, STREAM_SEEK_SET
, NULL
);
273 IStream_Release(stream
);
277 hr
= IStream_Stat(stream
, &stat
, STATFLAG_NONAME
);
279 CoReleaseMarshalData(stream
);
280 IStream_Release(stream
);
282 }else if(stat
.cbSize
.u
.HighPart
) {
283 FIXME("stream size to big\n");
284 CoReleaseMarshalData(stream
);
285 IStream_Release(stream
);
289 mapping
= CreateFileMappingW(INVALID_HANDLE_VALUE
, NULL
, PAGE_READWRITE
,
290 stat
.cbSize
.u
.HighPart
, stat
.cbSize
.u
.LowPart
, NULL
);
292 CoReleaseMarshalData(stream
);
293 IStream_Release(stream
);
297 view
= MapViewOfFile(mapping
, FILE_MAP_WRITE
, 0, 0, 0);
299 CloseHandle(mapping
);
300 CoReleaseMarshalData(stream
);
301 IStream_Release(stream
);
305 hr
= IStream_Read(stream
, view
, stat
.cbSize
.u
.LowPart
, NULL
);
306 UnmapViewOfFile(view
);
308 CloseHandle(mapping
);
309 hr
= IStream_Seek(stream
, seek_zero
, STREAM_SEEK_SET
, NULL
);
311 CoReleaseMarshalData(stream
);
312 IStream_Release(stream
);
317 memcpy(atom_str
, lresult_atom_prefix
, sizeof(lresult_atom_prefix
));
318 sprintfW(atom_str
+sizeof(lresult_atom_prefix
)/sizeof(WCHAR
),
319 atom_fmt
, GetCurrentProcessId(), HandleToUlong(mapping
), stat
.cbSize
.u
.LowPart
);
320 atom
= GlobalAddAtomW(atom_str
);
322 CloseHandle(mapping
);
323 hr
= IStream_Seek(stream
, seek_zero
, STREAM_SEEK_SET
, NULL
);
325 CoReleaseMarshalData(stream
);
326 IStream_Release(stream
);
330 IStream_Release(stream
);
334 HRESULT WINAPI
AccessibleObjectFromPoint( POINT ptScreen
, IAccessible
** ppacc
, VARIANT
* pvarChild
)
336 FIXME("{%d,%d} %p %p: stub\n", ptScreen
.x
, ptScreen
.y
, ppacc
, pvarChild
);
340 HRESULT WINAPI
AccessibleObjectFromWindow( HWND hwnd
, DWORD dwObjectID
,
341 REFIID riid
, void** ppvObject
)
343 TRACE("%p %d %s %p\n", hwnd
, dwObjectID
,
344 debugstr_guid( riid
), ppvObject
);
353 lres
= SendMessageW(hwnd
, WM_GETOBJECT
, 0xffffffff, dwObjectID
);
357 return ObjectFromLresult(lres
, riid
, 0, ppvObject
);
360 return CreateStdAccessibleObject(hwnd
, dwObjectID
, riid
, ppvObject
);
363 HRESULT WINAPI
WindowFromAccessibleObject(IAccessible
*acc
, HWND
*phwnd
)
369 TRACE("%p %p\n", acc
, phwnd
);
371 IAccessible_AddRef(acc
);
373 hres
= IAccessible_QueryInterface(acc
, &IID_IOleWindow
, (void**)&ow
);
374 if(SUCCEEDED(hres
)) {
375 hres
= IOleWindow_GetWindow(ow
, phwnd
);
376 IOleWindow_Release(ow
);
377 IAccessible_Release(acc
);
381 hres
= IAccessible_get_accParent(acc
, &parent
);
382 IAccessible_Release(acc
);
385 if(hres
!=S_OK
|| !parent
) {
390 hres
= IDispatch_QueryInterface(parent
, &IID_IAccessible
, (void**)&acc
);
391 IDispatch_Release(parent
);
397 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
,
400 TRACE("%p, %d, %p\n", hinstDLL
, fdwReason
, lpvReserved
);
404 case DLL_PROCESS_ATTACH
:
405 oleacc_handle
= hinstDLL
;
406 DisableThreadLibraryCalls(hinstDLL
);
412 HRESULT WINAPI
DllRegisterServer(void)
415 return __wine_register_resources(oleacc_handle
);
418 HRESULT WINAPI
DllUnregisterServer(void)
421 return __wine_unregister_resources(oleacc_handle
);
424 void WINAPI
GetOleaccVersionInfo(DWORD
* pVersion
, DWORD
* pBuild
)
426 *pVersion
= MAKELONG(0,7); /* Windows 7 version of oleacc: 7.0.0.0 */
427 *pBuild
= MAKELONG(0,0);
430 HANDLE WINAPI
GetProcessHandleFromHwnd(HWND hwnd
)
436 if(!GetWindowThreadProcessId(hwnd
, &proc_id
))
438 return OpenProcess(PROCESS_DUP_HANDLE
| PROCESS_VM_OPERATION
|
439 PROCESS_VM_READ
| PROCESS_VM_WRITE
| SYNCHRONIZE
, TRUE
, proc_id
);
442 UINT WINAPI
GetRoleTextW(DWORD role
, LPWSTR lpRole
, UINT rolemax
)
447 TRACE("%u %p %u\n", role
, lpRole
, rolemax
);
449 /* return role text length */
451 return LoadStringW(oleacc_handle
, role
, (LPWSTR
)&resptr
, 0);
453 ret
= LoadStringW(oleacc_handle
, role
, lpRole
, rolemax
);
455 if(rolemax
> 0) lpRole
[0] = '\0';
462 UINT WINAPI
GetRoleTextA(DWORD role
, LPSTR lpRole
, UINT rolemax
)
467 TRACE("%u %p %u\n", role
, lpRole
, rolemax
);
469 if(lpRole
&& !rolemax
)
472 length
= GetRoleTextW(role
, NULL
, 0);
474 if(lpRole
&& rolemax
)
479 roletextW
= HeapAlloc(GetProcessHeap(), 0, (length
+ 1)*sizeof(WCHAR
));
483 GetRoleTextW(role
, roletextW
, length
+ 1);
485 length
= WideCharToMultiByte( CP_ACP
, 0, roletextW
, -1, NULL
, 0, NULL
, NULL
);
488 HeapFree(GetProcessHeap(), 0, roletextW
);
492 if(rolemax
< length
) {
493 HeapFree(GetProcessHeap(), 0, roletextW
);
498 WideCharToMultiByte( CP_ACP
, 0, roletextW
, -1, lpRole
, rolemax
, NULL
, NULL
);
500 if(rolemax
< length
){
501 lpRole
[rolemax
-1] = '\0';
505 HeapFree(GetProcessHeap(), 0, roletextW
);
510 UINT WINAPI
GetStateTextW(DWORD state_bit
, WCHAR
*state_str
, UINT state_str_len
)
514 TRACE("%x %p %u\n", state_bit
, state_str
, state_str_len
);
516 if(state_bit
& ~(STATE_SYSTEM_VALID
| STATE_SYSTEM_HASPOPUP
)) {
517 if(state_str
&& state_str_len
)
522 state_id
= IDS_STATE_NORMAL
;
529 UINT ret
= LoadStringW(oleacc_handle
, state_id
, state_str
, state_str_len
);
530 if(!ret
&& state_str_len
)
535 return LoadStringW(oleacc_handle
, state_id
, (WCHAR
*)&tmp
, 0);
540 UINT WINAPI
GetStateTextA(DWORD state_bit
, CHAR
*state_str
, UINT state_str_len
)
544 TRACE("%x %p %u\n", state_bit
, state_str
, state_str_len
);
546 if(state_str
&& !state_str_len
)
549 if(state_bit
& ~(STATE_SYSTEM_VALID
| STATE_SYSTEM_HASPOPUP
)) {
550 if(state_str
&& state_str_len
)
555 state_id
= IDS_STATE_NORMAL
;
562 UINT ret
= LoadStringA(oleacc_handle
, state_id
, state_str
, state_str_len
);
563 if(!ret
&& state_str_len
)
568 return LoadStringA(oleacc_handle
, state_id
, tmp
, sizeof(tmp
));
572 HRESULT WINAPI
AccessibleChildren(IAccessible
*container
,
573 LONG start
, LONG count
, VARIANT
*children
, LONG
*children_cnt
)
579 TRACE("%p %d %d %p %p\n", container
, start
, count
, children
, children_cnt
);
581 if(!container
|| !children
|| !children_cnt
)
584 for(i
=0; i
<count
; i
++)
585 VariantInit(children
+i
);
587 hr
= IAccessible_QueryInterface(container
, &IID_IEnumVARIANT
, (void**)&ev
);
589 hr
= IEnumVARIANT_Reset(ev
);
591 hr
= IEnumVARIANT_Skip(ev
, start
);
593 hr
= IEnumVARIANT_Next(ev
, count
, children
, (ULONG
*)children_cnt
);
594 IEnumVARIANT_Release(ev
);
598 hr
= IAccessible_get_accChildCount(container
, &child_no
);
602 for(i
=0; i
<count
&& start
+i
+1<=child_no
; i
++) {
605 V_VT(children
+i
) = VT_I4
;
606 V_I4(children
+i
) = start
+i
+1;
608 hr
= IAccessible_get_accChild(container
, children
[i
], &disp
);
609 if(SUCCEEDED(hr
) && disp
) {
610 V_VT(children
+i
) = VT_DISPATCH
;
611 V_DISPATCH(children
+i
) = disp
;
616 return i
==count
? S_OK
: S_FALSE
;