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
21 #include "oleacc_private.h"
26 #include <wine/unicode.h>
30 static const WCHAR lresult_atom_prefix
[] = {'w','i','n','e','_','o','l','e','a','c','c',':'};
32 static const WCHAR menuW
[] = {'#','3','2','7','6','8',0};
33 static const WCHAR desktopW
[] = {'#','3','2','7','6','9',0};
34 static const WCHAR dialogW
[] = {'#','3','2','7','7','0',0};
35 static const WCHAR winswitchW
[] = {'#','3','2','7','7','1',0};
36 static const WCHAR mdi_clientW
[] = {'M','D','I','C','l','i','e','n','t',0};
37 static const WCHAR richeditW
[] = {'R','I','C','H','E','D','I','T',0};
38 static const WCHAR richedit20aW
[] = {'R','i','c','h','E','d','i','t','2','0','A',0};
39 static const WCHAR richedit20wW
[] = {'R','i','c','h','E','d','i','t','2','0','W',0};
41 typedef HRESULT (WINAPI
*accessible_create
)(HWND
, const IID
*, void**);
46 accessible_create create_client
;
47 accessible_create create_window
;
48 } builtin_classes
[] = {
49 {WC_LISTBOXW
, 0x10000, NULL
, NULL
},
50 {menuW
, 0x10001, NULL
, NULL
},
51 {WC_BUTTONW
, 0x10002, NULL
, NULL
},
52 {WC_STATICW
, 0x10003, NULL
, NULL
},
53 {WC_EDITW
, 0x10004, NULL
, NULL
},
54 {WC_COMBOBOXW
, 0x10005, NULL
, NULL
},
55 {dialogW
, 0x10006, NULL
, NULL
},
56 {winswitchW
, 0x10007, NULL
, NULL
},
57 {mdi_clientW
, 0x10008, NULL
, NULL
},
58 {desktopW
, 0x10009, NULL
, NULL
},
59 {WC_SCROLLBARW
, 0x1000a, NULL
, NULL
},
60 {STATUSCLASSNAMEW
, 0x1000b, NULL
, NULL
},
61 {TOOLBARCLASSNAMEW
, 0x1000c, NULL
, NULL
},
62 {PROGRESS_CLASSW
, 0x1000d, NULL
, NULL
},
63 {ANIMATE_CLASSW
, 0x1000e, NULL
, NULL
},
64 {WC_TABCONTROLW
, 0x1000f, NULL
, NULL
},
65 {HOTKEY_CLASSW
, 0x10010, NULL
, NULL
},
66 {WC_HEADERW
, 0x10011, NULL
, NULL
},
67 {TRACKBAR_CLASSW
, 0x10012, NULL
, NULL
},
68 {WC_LISTVIEWW
, 0x10013, NULL
, NULL
},
69 {UPDOWN_CLASSW
, 0x10016, NULL
, NULL
},
70 {TOOLTIPS_CLASSW
, 0x10018, NULL
, NULL
},
71 {WC_TREEVIEWW
, 0x10019, NULL
, NULL
},
72 {MONTHCAL_CLASSW
, 0, NULL
, NULL
},
73 {DATETIMEPICK_CLASSW
, 0, NULL
, NULL
},
74 {WC_IPADDRESSW
, 0, NULL
, NULL
},
75 {richeditW
, 0x1001c, NULL
, NULL
},
76 {richedit20aW
, 0, NULL
, NULL
},
77 {richedit20wW
, 0, NULL
, NULL
},
80 static HINSTANCE oleacc_handle
= 0;
82 int convert_child_id(VARIANT
*v
)
88 FIXME("unhandled child ID variant type: %d\n", V_VT(v
));
93 static accessible_create
get_builtin_accessible_obj(HWND hwnd
, LONG objid
)
98 if(!RealGetWindowClassW(hwnd
, class_name
, sizeof(class_name
)/sizeof(WCHAR
)))
100 TRACE("got window class: %s\n", debugstr_w(class_name
));
102 for(i
=0; i
<sizeof(builtin_classes
)/sizeof(builtin_classes
[0]); i
++) {
103 if(!strcmpiW(class_name
, builtin_classes
[i
].name
)) {
104 accessible_create ret
;
106 ret
= (objid
==OBJID_CLIENT
?
107 builtin_classes
[i
].create_client
:
108 builtin_classes
[i
].create_window
);
110 FIXME("unhandled window class: %s\n", debugstr_w(class_name
));
115 idx
= SendMessageW(hwnd
, WM_GETOBJECT
, 0, OBJID_QUERYCLASSNAMEIDX
);
117 for(i
=0; i
<sizeof(builtin_classes
)/sizeof(builtin_classes
[0]); i
++) {
118 if(idx
== builtin_classes
[i
].idx
) {
119 accessible_create ret
;
121 ret
= (objid
==OBJID_CLIENT
?
122 builtin_classes
[i
].create_client
:
123 builtin_classes
[i
].create_window
);
125 FIXME("unhandled class name idx: %x\n", idx
);
130 WARN("unhandled class name idx: %x\n", idx
);
136 HRESULT WINAPI
CreateStdAccessibleObject( HWND hwnd
, LONG idObject
,
137 REFIID riidInterface
, void** ppvObject
)
139 accessible_create create
;
141 TRACE("%p %d %s %p\n", hwnd
, idObject
,
142 debugstr_guid( riidInterface
), ppvObject
);
146 create
= get_builtin_accessible_obj(hwnd
, idObject
);
147 if(create
) return create(hwnd
, riidInterface
, ppvObject
);
148 return create_client_object(hwnd
, riidInterface
, ppvObject
);
150 create
= get_builtin_accessible_obj(hwnd
, idObject
);
151 if(create
) return create(hwnd
, riidInterface
, ppvObject
);
152 return create_window_object(hwnd
, riidInterface
, ppvObject
);
154 FIXME("unhandled object id: %d\n", idObject
);
159 HRESULT WINAPI
ObjectFromLresult( LRESULT result
, REFIID riid
, WPARAM wParam
, void **ppObject
)
161 WCHAR atom_str
[sizeof(lresult_atom_prefix
)/sizeof(WCHAR
)+3*8+3];
162 HANDLE server_proc
, server_mapping
, mapping
;
170 TRACE("%ld %s %ld %p\n", result
, debugstr_guid(riid
), wParam
, ppObject
);
173 FIXME("unsupported wParam = %lx\n", wParam
);
179 if(result
!= (ATOM
)result
)
182 if(!GlobalGetAtomNameW(result
, atom_str
, sizeof(atom_str
)/sizeof(WCHAR
)))
184 if(memcmp(atom_str
, lresult_atom_prefix
, sizeof(lresult_atom_prefix
)))
186 p
= atom_str
+ sizeof(lresult_atom_prefix
)/sizeof(WCHAR
);
187 proc_id
= strtoulW(p
, &p
, 16);
190 server_mapping
= ULongToHandle( strtoulW(p
+1, &p
, 16) );
193 size
= strtoulW(p
+1, &p
, 16);
197 server_proc
= OpenProcess(PROCESS_DUP_HANDLE
, FALSE
, proc_id
);
201 if(!DuplicateHandle(server_proc
, server_mapping
, GetCurrentProcess(), &mapping
,
202 0, FALSE
, DUPLICATE_CLOSE_SOURCE
|DUPLICATE_SAME_ACCESS
))
204 CloseHandle(server_proc
);
205 GlobalDeleteAtom(result
);
207 view
= MapViewOfFile(mapping
, FILE_MAP_READ
, 0, 0, 0);
208 CloseHandle(mapping
);
212 data
= GlobalAlloc(GMEM_FIXED
, size
);
213 memcpy(data
, view
, size
);
214 UnmapViewOfFile(view
);
216 return E_OUTOFMEMORY
;
218 hr
= CreateStreamOnHGlobal(data
, TRUE
, &stream
);
224 hr
= CoUnmarshalInterface(stream
, riid
, ppObject
);
225 IStream_Release(stream
);
229 LRESULT WINAPI
LresultFromObject( REFIID riid
, WPARAM wParam
, LPUNKNOWN pAcc
)
231 static const WCHAR atom_fmt
[] = {'%','0','8','x',':','%','0','8','x',':','%','0','8','x',0};
232 static const LARGE_INTEGER seek_zero
= {{0}};
234 WCHAR atom_str
[sizeof(lresult_atom_prefix
)/sizeof(WCHAR
)+3*8+3];
242 TRACE("%s %ld %p\n", debugstr_guid(riid
), wParam
, pAcc
);
245 FIXME("unsupported wParam = %lx\n", wParam
);
250 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &stream
);
254 hr
= CoMarshalInterface(stream
, riid
, pAcc
, MSHCTX_LOCAL
, NULL
, MSHLFLAGS_NORMAL
);
256 IStream_Release(stream
);
260 hr
= IStream_Seek(stream
, seek_zero
, STREAM_SEEK_SET
, NULL
);
262 IStream_Release(stream
);
266 hr
= IStream_Stat(stream
, &stat
, STATFLAG_NONAME
);
268 CoReleaseMarshalData(stream
);
269 IStream_Release(stream
);
271 }else if(stat
.cbSize
.u
.HighPart
) {
272 FIXME("stream size to big\n");
273 CoReleaseMarshalData(stream
);
274 IStream_Release(stream
);
278 mapping
= CreateFileMappingW(INVALID_HANDLE_VALUE
, NULL
, PAGE_READWRITE
,
279 stat
.cbSize
.u
.HighPart
, stat
.cbSize
.u
.LowPart
, NULL
);
281 CoReleaseMarshalData(stream
);
282 IStream_Release(stream
);
286 view
= MapViewOfFile(mapping
, FILE_MAP_WRITE
, 0, 0, 0);
288 CloseHandle(mapping
);
289 CoReleaseMarshalData(stream
);
290 IStream_Release(stream
);
294 hr
= IStream_Read(stream
, view
, stat
.cbSize
.u
.LowPart
, NULL
);
295 UnmapViewOfFile(view
);
297 CloseHandle(mapping
);
298 hr
= IStream_Seek(stream
, seek_zero
, STREAM_SEEK_SET
, NULL
);
300 CoReleaseMarshalData(stream
);
301 IStream_Release(stream
);
306 memcpy(atom_str
, lresult_atom_prefix
, sizeof(lresult_atom_prefix
));
307 sprintfW(atom_str
+sizeof(lresult_atom_prefix
)/sizeof(WCHAR
),
308 atom_fmt
, GetCurrentProcessId(), HandleToUlong(mapping
), stat
.cbSize
.u
.LowPart
);
309 atom
= GlobalAddAtomW(atom_str
);
311 CloseHandle(mapping
);
312 hr
= IStream_Seek(stream
, seek_zero
, STREAM_SEEK_SET
, NULL
);
314 CoReleaseMarshalData(stream
);
315 IStream_Release(stream
);
319 IStream_Release(stream
);
323 HRESULT WINAPI
AccessibleObjectFromPoint( POINT ptScreen
, IAccessible
** ppacc
, VARIANT
* pvarChild
)
325 FIXME("{%d,%d} %p %p: stub\n", ptScreen
.x
, ptScreen
.y
, ppacc
, pvarChild
);
329 HRESULT WINAPI
AccessibleObjectFromWindow( HWND hwnd
, DWORD dwObjectID
,
330 REFIID riid
, void** ppvObject
)
332 TRACE("%p %d %s %p\n", hwnd
, dwObjectID
,
333 debugstr_guid( riid
), ppvObject
);
342 lres
= SendMessageW(hwnd
, WM_GETOBJECT
, 0xffffffff, dwObjectID
);
346 return ObjectFromLresult(lres
, riid
, 0, ppvObject
);
349 return CreateStdAccessibleObject(hwnd
, dwObjectID
, riid
, ppvObject
);
352 HRESULT WINAPI
WindowFromAccessibleObject(IAccessible
*acc
, HWND
*phwnd
)
358 TRACE("%p %p\n", acc
, phwnd
);
360 IAccessible_AddRef(acc
);
362 hres
= IAccessible_QueryInterface(acc
, &IID_IOleWindow
, (void**)&ow
);
363 if(SUCCEEDED(hres
)) {
364 hres
= IOleWindow_GetWindow(ow
, phwnd
);
365 IOleWindow_Release(ow
);
366 IAccessible_Release(acc
);
370 hres
= IAccessible_get_accParent(acc
, &parent
);
371 IAccessible_Release(acc
);
374 if(hres
!=S_OK
|| !parent
) {
379 hres
= IDispatch_QueryInterface(parent
, &IID_IAccessible
, (void**)&acc
);
380 IDispatch_Release(parent
);
386 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
,
389 TRACE("%p, %d, %p\n", hinstDLL
, fdwReason
, lpvReserved
);
393 case DLL_PROCESS_ATTACH
:
394 oleacc_handle
= hinstDLL
;
395 DisableThreadLibraryCalls(hinstDLL
);
401 HRESULT WINAPI
DllRegisterServer(void)
404 return __wine_register_resources(oleacc_handle
);
407 HRESULT WINAPI
DllUnregisterServer(void)
410 return __wine_unregister_resources(oleacc_handle
);
413 void WINAPI
GetOleaccVersionInfo(DWORD
* pVersion
, DWORD
* pBuild
)
415 *pVersion
= MAKELONG(2,4); /* Windows XP version of oleacc: 4.2.5406.0 */
416 *pBuild
= MAKELONG(0,5406);
419 HANDLE WINAPI
GetProcessHandleFromHwnd(HWND hwnd
)
425 if(!GetWindowThreadProcessId(hwnd
, &proc_id
))
427 return OpenProcess(PROCESS_DUP_HANDLE
| PROCESS_VM_OPERATION
|
428 PROCESS_VM_READ
| PROCESS_VM_WRITE
| SYNCHRONIZE
, TRUE
, proc_id
);
431 UINT WINAPI
GetRoleTextW(DWORD role
, LPWSTR lpRole
, UINT rolemax
)
436 TRACE("%u %p %u\n", role
, lpRole
, rolemax
);
438 /* return role text length */
440 return LoadStringW(oleacc_handle
, role
, (LPWSTR
)&resptr
, 0);
442 ret
= LoadStringW(oleacc_handle
, role
, lpRole
, rolemax
);
444 if(rolemax
> 0) lpRole
[0] = '\0';
451 UINT WINAPI
GetRoleTextA(DWORD role
, LPSTR lpRole
, UINT rolemax
)
456 TRACE("%u %p %u\n", role
, lpRole
, rolemax
);
458 if(lpRole
&& !rolemax
)
461 length
= GetRoleTextW(role
, NULL
, 0);
463 if(lpRole
&& rolemax
)
468 roletextW
= HeapAlloc(GetProcessHeap(), 0, (length
+ 1)*sizeof(WCHAR
));
472 GetRoleTextW(role
, roletextW
, length
+ 1);
474 length
= WideCharToMultiByte( CP_ACP
, 0, roletextW
, -1, NULL
, 0, NULL
, NULL
);
477 HeapFree(GetProcessHeap(), 0, roletextW
);
481 if(rolemax
< length
) {
482 HeapFree(GetProcessHeap(), 0, roletextW
);
487 WideCharToMultiByte( CP_ACP
, 0, roletextW
, -1, lpRole
, rolemax
, NULL
, NULL
);
489 if(rolemax
< length
){
490 lpRole
[rolemax
-1] = '\0';
494 HeapFree(GetProcessHeap(), 0, roletextW
);
499 UINT WINAPI
GetStateTextW(DWORD state_bit
, WCHAR
*state_str
, UINT state_str_len
)
503 TRACE("%x %p %u\n", state_bit
, state_str
, state_str_len
);
505 if(state_bit
& ~(STATE_SYSTEM_VALID
| STATE_SYSTEM_HASPOPUP
)) {
506 if(state_str
&& state_str_len
)
511 state_id
= IDS_STATE_NORMAL
;
518 UINT ret
= LoadStringW(oleacc_handle
, state_id
, state_str
, state_str_len
);
519 if(!ret
&& state_str_len
)
524 return LoadStringW(oleacc_handle
, state_id
, (WCHAR
*)&tmp
, 0);
529 UINT WINAPI
GetStateTextA(DWORD state_bit
, CHAR
*state_str
, UINT state_str_len
)
533 TRACE("%x %p %u\n", state_bit
, state_str
, state_str_len
);
535 if(state_str
&& !state_str_len
)
538 if(state_bit
& ~(STATE_SYSTEM_VALID
| STATE_SYSTEM_HASPOPUP
)) {
539 if(state_str
&& state_str_len
)
544 state_id
= IDS_STATE_NORMAL
;
551 UINT ret
= LoadStringA(oleacc_handle
, state_id
, state_str
, state_str_len
);
552 if(!ret
&& state_str_len
)
557 return LoadStringA(oleacc_handle
, state_id
, tmp
, sizeof(tmp
));