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 return E_OUTOFMEMORY
;
224 memcpy(data
, view
, size
);
225 UnmapViewOfFile(view
);
227 hr
= CreateStreamOnHGlobal(data
, TRUE
, &stream
);
233 hr
= CoUnmarshalInterface(stream
, riid
, ppObject
);
234 IStream_Release(stream
);
238 LRESULT WINAPI
LresultFromObject( REFIID riid
, WPARAM wParam
, LPUNKNOWN pAcc
)
240 static const WCHAR atom_fmt
[] = {'%','0','8','x',':','%','0','8','x',':','%','0','8','x',0};
241 static const LARGE_INTEGER seek_zero
= {{0}};
243 WCHAR atom_str
[sizeof(lresult_atom_prefix
)/sizeof(WCHAR
)+3*8+3];
251 TRACE("%s %ld %p\n", debugstr_guid(riid
), wParam
, pAcc
);
254 FIXME("unsupported wParam = %lx\n", wParam
);
259 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &stream
);
263 hr
= CoMarshalInterface(stream
, riid
, pAcc
, MSHCTX_LOCAL
, NULL
, MSHLFLAGS_NORMAL
);
265 IStream_Release(stream
);
269 hr
= IStream_Seek(stream
, seek_zero
, STREAM_SEEK_SET
, NULL
);
271 IStream_Release(stream
);
275 hr
= IStream_Stat(stream
, &stat
, STATFLAG_NONAME
);
277 CoReleaseMarshalData(stream
);
278 IStream_Release(stream
);
280 }else if(stat
.cbSize
.u
.HighPart
) {
281 FIXME("stream size to big\n");
282 CoReleaseMarshalData(stream
);
283 IStream_Release(stream
);
287 mapping
= CreateFileMappingW(INVALID_HANDLE_VALUE
, NULL
, PAGE_READWRITE
,
288 stat
.cbSize
.u
.HighPart
, stat
.cbSize
.u
.LowPart
, NULL
);
290 CoReleaseMarshalData(stream
);
291 IStream_Release(stream
);
295 view
= MapViewOfFile(mapping
, FILE_MAP_WRITE
, 0, 0, 0);
297 CloseHandle(mapping
);
298 CoReleaseMarshalData(stream
);
299 IStream_Release(stream
);
303 hr
= IStream_Read(stream
, view
, stat
.cbSize
.u
.LowPart
, NULL
);
304 UnmapViewOfFile(view
);
306 CloseHandle(mapping
);
307 hr
= IStream_Seek(stream
, seek_zero
, STREAM_SEEK_SET
, NULL
);
309 CoReleaseMarshalData(stream
);
310 IStream_Release(stream
);
315 memcpy(atom_str
, lresult_atom_prefix
, sizeof(lresult_atom_prefix
));
316 sprintfW(atom_str
+sizeof(lresult_atom_prefix
)/sizeof(WCHAR
),
317 atom_fmt
, GetCurrentProcessId(), HandleToUlong(mapping
), stat
.cbSize
.u
.LowPart
);
318 atom
= GlobalAddAtomW(atom_str
);
320 CloseHandle(mapping
);
321 hr
= IStream_Seek(stream
, seek_zero
, STREAM_SEEK_SET
, NULL
);
323 CoReleaseMarshalData(stream
);
324 IStream_Release(stream
);
328 IStream_Release(stream
);
332 HRESULT WINAPI
AccessibleObjectFromPoint( POINT ptScreen
, IAccessible
** ppacc
, VARIANT
* pvarChild
)
334 FIXME("{%d,%d} %p %p: stub\n", ptScreen
.x
, ptScreen
.y
, ppacc
, pvarChild
);
338 HRESULT WINAPI
AccessibleObjectFromWindow( HWND hwnd
, DWORD dwObjectID
,
339 REFIID riid
, void** ppvObject
)
341 TRACE("%p %d %s %p\n", hwnd
, dwObjectID
,
342 debugstr_guid( riid
), ppvObject
);
351 lres
= SendMessageW(hwnd
, WM_GETOBJECT
, 0xffffffff, dwObjectID
);
355 return ObjectFromLresult(lres
, riid
, 0, ppvObject
);
358 return CreateStdAccessibleObject(hwnd
, dwObjectID
, riid
, ppvObject
);
361 HRESULT WINAPI
WindowFromAccessibleObject(IAccessible
*acc
, HWND
*phwnd
)
367 TRACE("%p %p\n", acc
, phwnd
);
369 IAccessible_AddRef(acc
);
371 hres
= IAccessible_QueryInterface(acc
, &IID_IOleWindow
, (void**)&ow
);
372 if(SUCCEEDED(hres
)) {
373 hres
= IOleWindow_GetWindow(ow
, phwnd
);
374 IOleWindow_Release(ow
);
375 IAccessible_Release(acc
);
379 hres
= IAccessible_get_accParent(acc
, &parent
);
380 IAccessible_Release(acc
);
383 if(hres
!=S_OK
|| !parent
) {
388 hres
= IDispatch_QueryInterface(parent
, &IID_IAccessible
, (void**)&acc
);
389 IDispatch_Release(parent
);
395 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
,
398 TRACE("%p, %d, %p\n", hinstDLL
, fdwReason
, lpvReserved
);
402 case DLL_PROCESS_ATTACH
:
403 oleacc_handle
= hinstDLL
;
404 DisableThreadLibraryCalls(hinstDLL
);
410 HRESULT WINAPI
DllRegisterServer(void)
413 return __wine_register_resources(oleacc_handle
);
416 HRESULT WINAPI
DllUnregisterServer(void)
419 return __wine_unregister_resources(oleacc_handle
);
422 void WINAPI
GetOleaccVersionInfo(DWORD
* pVersion
, DWORD
* pBuild
)
424 *pVersion
= MAKELONG(0,7); /* Windows 7 version of oleacc: 7.0.0.0 */
425 *pBuild
= MAKELONG(0,0);
428 HANDLE WINAPI
GetProcessHandleFromHwnd(HWND hwnd
)
434 if(!GetWindowThreadProcessId(hwnd
, &proc_id
))
436 return OpenProcess(PROCESS_DUP_HANDLE
| PROCESS_VM_OPERATION
|
437 PROCESS_VM_READ
| PROCESS_VM_WRITE
| SYNCHRONIZE
, TRUE
, proc_id
);
440 UINT WINAPI
GetRoleTextW(DWORD role
, LPWSTR lpRole
, UINT rolemax
)
445 TRACE("%u %p %u\n", role
, lpRole
, rolemax
);
447 /* return role text length */
449 return LoadStringW(oleacc_handle
, role
, (LPWSTR
)&resptr
, 0);
451 ret
= LoadStringW(oleacc_handle
, role
, lpRole
, rolemax
);
453 if(rolemax
> 0) lpRole
[0] = '\0';
460 UINT WINAPI
GetRoleTextA(DWORD role
, LPSTR lpRole
, UINT rolemax
)
465 TRACE("%u %p %u\n", role
, lpRole
, rolemax
);
467 if(lpRole
&& !rolemax
)
470 length
= GetRoleTextW(role
, NULL
, 0);
472 if(lpRole
&& rolemax
)
477 roletextW
= HeapAlloc(GetProcessHeap(), 0, (length
+ 1)*sizeof(WCHAR
));
481 GetRoleTextW(role
, roletextW
, length
+ 1);
483 length
= WideCharToMultiByte( CP_ACP
, 0, roletextW
, -1, NULL
, 0, NULL
, NULL
);
486 HeapFree(GetProcessHeap(), 0, roletextW
);
490 if(rolemax
< length
) {
491 HeapFree(GetProcessHeap(), 0, roletextW
);
496 WideCharToMultiByte( CP_ACP
, 0, roletextW
, -1, lpRole
, rolemax
, NULL
, NULL
);
498 if(rolemax
< length
){
499 lpRole
[rolemax
-1] = '\0';
503 HeapFree(GetProcessHeap(), 0, roletextW
);
508 UINT WINAPI
GetStateTextW(DWORD state_bit
, WCHAR
*state_str
, UINT state_str_len
)
512 TRACE("%x %p %u\n", state_bit
, state_str
, state_str_len
);
514 if(state_bit
& ~(STATE_SYSTEM_VALID
| STATE_SYSTEM_HASPOPUP
)) {
515 if(state_str
&& state_str_len
)
520 state_id
= IDS_STATE_NORMAL
;
527 UINT ret
= LoadStringW(oleacc_handle
, state_id
, state_str
, state_str_len
);
528 if(!ret
&& state_str_len
)
533 return LoadStringW(oleacc_handle
, state_id
, (WCHAR
*)&tmp
, 0);
538 UINT WINAPI
GetStateTextA(DWORD state_bit
, CHAR
*state_str
, UINT state_str_len
)
542 TRACE("%x %p %u\n", state_bit
, state_str
, state_str_len
);
544 if(state_str
&& !state_str_len
)
547 if(state_bit
& ~(STATE_SYSTEM_VALID
| STATE_SYSTEM_HASPOPUP
)) {
548 if(state_str
&& state_str_len
)
553 state_id
= IDS_STATE_NORMAL
;
560 UINT ret
= LoadStringA(oleacc_handle
, state_id
, state_str
, state_str_len
);
561 if(!ret
&& state_str_len
)
566 return LoadStringA(oleacc_handle
, state_id
, tmp
, sizeof(tmp
));