Sync with trunk r64509.
[reactos.git] / dll / win32 / oleacc / window.c
1 /*
2 * Copyright 2014 Piotr Caban for CodeWeavers
3 *
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.
8 *
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.
13 *
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
17 */
18
19 #include "oleacc_private.h"
20
21 typedef struct {
22 IAccessible IAccessible_iface;
23 IOleWindow IOleWindow_iface;
24
25 LONG ref;
26 } Window;
27
28 static inline Window* impl_from_Window(IAccessible *iface)
29 {
30 return CONTAINING_RECORD(iface, Window, IAccessible_iface);
31 }
32
33 static HRESULT WINAPI Window_QueryInterface(IAccessible *iface, REFIID riid, void **ppv)
34 {
35 Window *This = impl_from_Window(iface);
36
37 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
38
39 if(IsEqualIID(riid, &IID_IAccessible) ||
40 IsEqualIID(riid, &IID_IDispatch) ||
41 IsEqualIID(riid, &IID_IUnknown)) {
42 *ppv = iface;
43 }else if(IsEqualIID(riid, &IID_IOleWindow)) {
44 *ppv = &This->IOleWindow_iface;
45 }else {
46 WARN("no interface: %s\n", debugstr_guid(riid));
47 *ppv = NULL;
48 return E_NOINTERFACE;
49 }
50
51 IAccessible_AddRef(iface);
52 return S_OK;
53 }
54
55 static ULONG WINAPI Window_AddRef(IAccessible *iface)
56 {
57 Window *This = impl_from_Window(iface);
58 ULONG ref = InterlockedIncrement(&This->ref);
59
60 TRACE("(%p) ref = %u\n", This, ref);
61 return ref;
62 }
63
64 static ULONG WINAPI Window_Release(IAccessible *iface)
65 {
66 Window *This = impl_from_Window(iface);
67 ULONG ref = InterlockedDecrement(&This->ref);
68
69 TRACE("(%p) ref = %u\n", This, ref);
70
71 if(!ref)
72 heap_free(This);
73 return ref;
74 }
75
76 static HRESULT WINAPI Window_GetTypeInfoCount(IAccessible *iface, UINT *pctinfo)
77 {
78 Window *This = impl_from_Window(iface);
79 FIXME("(%p)->(%p)\n", This, pctinfo);
80 return E_NOTIMPL;
81 }
82
83 static HRESULT WINAPI Window_GetTypeInfo(IAccessible *iface,
84 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
85 {
86 Window *This = impl_from_Window(iface);
87 FIXME("(%p)->(%u %x %p)\n", This, iTInfo, lcid, ppTInfo);
88 return E_NOTIMPL;
89 }
90
91 static HRESULT WINAPI Window_GetIDsOfNames(IAccessible *iface, REFIID riid,
92 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
93 {
94 Window *This = impl_from_Window(iface);
95 FIXME("(%p)->(%s %p %u %x %p)\n", This, debugstr_guid(riid),
96 rgszNames, cNames, lcid, rgDispId);
97 return E_NOTIMPL;
98 }
99
100 static HRESULT WINAPI Window_Invoke(IAccessible *iface, DISPID dispIdMember,
101 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
102 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
103 {
104 Window *This = impl_from_Window(iface);
105 FIXME("(%p)->(%x %s %x %x %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
106 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
107 return E_NOTIMPL;
108 }
109
110 static HRESULT WINAPI Window_get_accParent(IAccessible *iface, IDispatch **ppdispParent)
111 {
112 Window *This = impl_from_Window(iface);
113 FIXME("(%p)->(%p)\n", This, ppdispParent);
114 return E_NOTIMPL;
115 }
116
117 static HRESULT WINAPI Window_get_accChildCount(IAccessible *iface, LONG *pcountChildren)
118 {
119 Window *This = impl_from_Window(iface);
120 FIXME("(%p)->(%p)\n", This, pcountChildren);
121 return E_NOTIMPL;
122 }
123
124 static HRESULT WINAPI Window_get_accChild(IAccessible *iface,
125 VARIANT varChildID, IDispatch **ppdispChild)
126 {
127 Window *This = impl_from_Window(iface);
128 FIXME("(%p)->(%s %p)\n", This, debugstr_variant(&varChildID), ppdispChild);
129 return E_NOTIMPL;
130 }
131
132 static HRESULT WINAPI Window_get_accName(IAccessible *iface, VARIANT varID, BSTR *pszName)
133 {
134 Window *This = impl_from_Window(iface);
135 FIXME("(%p)->(%s %p)\n", This, debugstr_variant(&varID), pszName);
136 return E_NOTIMPL;
137 }
138
139 static HRESULT WINAPI Window_get_accValue(IAccessible *iface, VARIANT varID, BSTR *pszValue)
140 {
141 Window *This = impl_from_Window(iface);
142 FIXME("(%p)->(%s %p)\n", This, debugstr_variant(&varID), pszValue);
143 return E_NOTIMPL;
144 }
145
146 static HRESULT WINAPI Window_get_accDescription(IAccessible *iface,
147 VARIANT varID, BSTR *pszDescription)
148 {
149 Window *This = impl_from_Window(iface);
150 FIXME("(%p)->(%s %p)\n", This, debugstr_variant(&varID), pszDescription);
151 return E_NOTIMPL;
152 }
153
154 static HRESULT WINAPI Window_get_accRole(IAccessible *iface, VARIANT varID, VARIANT *pvarRole)
155 {
156 Window *This = impl_from_Window(iface);
157 FIXME("(%p)->(%s %p)\n", This, debugstr_variant(&varID), pvarRole);
158 return E_NOTIMPL;
159 }
160
161 static HRESULT WINAPI Window_get_accState(IAccessible *iface, VARIANT varID, VARIANT *pvarState)
162 {
163 Window *This = impl_from_Window(iface);
164 FIXME("(%p)->(%s %p)\n", This, debugstr_variant(&varID), pvarState);
165 return E_NOTIMPL;
166 }
167
168 static HRESULT WINAPI Window_get_accHelp(IAccessible *iface, VARIANT varID, BSTR *pszHelp)
169 {
170 Window *This = impl_from_Window(iface);
171 FIXME("(%p)->(%s %p)\n", This, debugstr_variant(&varID), pszHelp);
172 return E_NOTIMPL;
173 }
174
175 static HRESULT WINAPI Window_get_accHelpTopic(IAccessible *iface,
176 BSTR *pszHelpFile, VARIANT varID, LONG *pidTopic)
177 {
178 Window *This = impl_from_Window(iface);
179 FIXME("(%p)->(%p %s %p)\n", This, pszHelpFile, debugstr_variant(&varID), pidTopic);
180 return E_NOTIMPL;
181 }
182
183 static HRESULT WINAPI Window_get_accKeyboardShortcut(IAccessible *iface,
184 VARIANT varID, BSTR *pszKeyboardShortcut)
185 {
186 Window *This = impl_from_Window(iface);
187 FIXME("(%p)->(%s %p)\n", This, debugstr_variant(&varID), pszKeyboardShortcut);
188 return E_NOTIMPL;
189 }
190
191 static HRESULT WINAPI Window_get_accFocus(IAccessible *iface, VARIANT *pvarID)
192 {
193 Window *This = impl_from_Window(iface);
194 FIXME("(%p)->(%p)\n", This, pvarID);
195 return E_NOTIMPL;
196 }
197
198 static HRESULT WINAPI Window_get_accSelection(IAccessible *iface, VARIANT *pvarID)
199 {
200 Window *This = impl_from_Window(iface);
201 FIXME("(%p)->(%p)\n", This, pvarID);
202 return E_NOTIMPL;
203 }
204
205 static HRESULT WINAPI Window_get_accDefaultAction(IAccessible *iface,
206 VARIANT varID, BSTR *pszDefaultAction)
207 {
208 Window *This = impl_from_Window(iface);
209 FIXME("(%p)->(%s %p)\n", This, debugstr_variant(&varID), pszDefaultAction);
210 return E_NOTIMPL;
211 }
212
213 static HRESULT WINAPI Window_accSelect(IAccessible *iface, LONG flagsSelect, VARIANT varID)
214 {
215 Window *This = impl_from_Window(iface);
216 FIXME("(%p)->(%x %s)\n", This, flagsSelect, debugstr_variant(&varID));
217 return E_NOTIMPL;
218 }
219
220 static HRESULT WINAPI Window_accLocation(IAccessible *iface, LONG *pxLeft,
221 LONG *pyTop, LONG *pcxWidth, LONG *pcyHeight, VARIANT varID)
222 {
223 Window *This = impl_from_Window(iface);
224 FIXME("(%p)->(%p %p %p %p %s)\n", This, pxLeft, pyTop,
225 pcxWidth, pcyHeight, debugstr_variant(&varID));
226 return E_NOTIMPL;
227 }
228
229 static HRESULT WINAPI Window_accNavigate(IAccessible *iface,
230 LONG navDir, VARIANT varStart, VARIANT *pvarEnd)
231 {
232 Window *This = impl_from_Window(iface);
233 FIXME("(%p)->(%d %s %p)\n", This, navDir, debugstr_variant(&varStart), pvarEnd);
234 return E_NOTIMPL;
235 }
236
237 static HRESULT WINAPI Window_accHitTest(IAccessible *iface,
238 LONG xLeft, LONG yTop, VARIANT *pvarID)
239 {
240 Window *This = impl_from_Window(iface);
241 FIXME("(%p)->(%d %d %p)\n", This, xLeft, yTop, pvarID);
242 return E_NOTIMPL;
243 }
244
245 static HRESULT WINAPI Window_accDoDefaultAction(IAccessible *iface, VARIANT varID)
246 {
247 Window *This = impl_from_Window(iface);
248 FIXME("(%p)->(%s)\n", This, debugstr_variant(&varID));
249 return E_NOTIMPL;
250 }
251
252 static HRESULT WINAPI Window_put_accName(IAccessible *iface, VARIANT varID, BSTR pszName)
253 {
254 Window *This = impl_from_Window(iface);
255 FIXME("(%p)->(%s %s)\n", This, debugstr_variant(&varID), debugstr_w(pszName));
256 return E_NOTIMPL;
257 }
258
259 static HRESULT WINAPI Window_put_accValue(IAccessible *iface, VARIANT varID, BSTR pszValue)
260 {
261 Window *This = impl_from_Window(iface);
262 FIXME("(%p)->(%s %s)\n", This, debugstr_variant(&varID), debugstr_w(pszValue));
263 return E_NOTIMPL;
264 }
265
266 static const IAccessibleVtbl WindowVtbl = {
267 Window_QueryInterface,
268 Window_AddRef,
269 Window_Release,
270 Window_GetTypeInfoCount,
271 Window_GetTypeInfo,
272 Window_GetIDsOfNames,
273 Window_Invoke,
274 Window_get_accParent,
275 Window_get_accChildCount,
276 Window_get_accChild,
277 Window_get_accName,
278 Window_get_accValue,
279 Window_get_accDescription,
280 Window_get_accRole,
281 Window_get_accState,
282 Window_get_accHelp,
283 Window_get_accHelpTopic,
284 Window_get_accKeyboardShortcut,
285 Window_get_accFocus,
286 Window_get_accSelection,
287 Window_get_accDefaultAction,
288 Window_accSelect,
289 Window_accLocation,
290 Window_accNavigate,
291 Window_accHitTest,
292 Window_accDoDefaultAction,
293 Window_put_accName,
294 Window_put_accValue
295 };
296
297 static inline Window* impl_from_Window_OleWindow(IOleWindow *iface)
298 {
299 return CONTAINING_RECORD(iface, Window, IOleWindow_iface);
300 }
301
302 static HRESULT WINAPI Window_OleWindow_QueryInterface(IOleWindow *iface, REFIID riid, void **ppv)
303 {
304 Window *This = impl_from_Window_OleWindow(iface);
305 return IAccessible_QueryInterface(&This->IAccessible_iface, riid, ppv);
306 }
307
308 static ULONG WINAPI Window_OleWindow_AddRef(IOleWindow *iface)
309 {
310 Window *This = impl_from_Window_OleWindow(iface);
311 return IAccessible_AddRef(&This->IAccessible_iface);
312 }
313
314 static ULONG WINAPI Window_OleWindow_Release(IOleWindow *iface)
315 {
316 Window *This = impl_from_Window_OleWindow(iface);
317 return IAccessible_Release(&This->IAccessible_iface);
318 }
319
320 static HRESULT WINAPI Window_OleWindow_GetWindow(IOleWindow *iface, HWND *phwnd)
321 {
322 Window *This = impl_from_Window_OleWindow(iface);
323 FIXME("(%p)->(%p)\n", This, phwnd);
324 return E_NOTIMPL;
325 }
326
327 static HRESULT WINAPI Window_OleWindow_ContextSensitiveHelp(IOleWindow *iface, BOOL fEnterMode)
328 {
329 Window *This = impl_from_Window_OleWindow(iface);
330 FIXME("(%p)->(%x)\n", This, fEnterMode);
331 return E_NOTIMPL;
332 }
333
334 static const IOleWindowVtbl WindowOleWindowVtbl = {
335 Window_OleWindow_QueryInterface,
336 Window_OleWindow_AddRef,
337 Window_OleWindow_Release,
338 Window_OleWindow_GetWindow,
339 Window_OleWindow_ContextSensitiveHelp
340 };
341
342 HRESULT create_window_object(HWND hwnd, const IID *iid, void **obj)
343 {
344 Window *window;
345 HRESULT hres;
346
347 if(!IsWindow(hwnd))
348 return E_FAIL;
349
350 window = heap_alloc_zero(sizeof(Window));
351 if(!window)
352 return E_OUTOFMEMORY;
353
354 window->IAccessible_iface.lpVtbl = &WindowVtbl;
355 window->IOleWindow_iface.lpVtbl = &WindowOleWindowVtbl;
356 window->ref = 1;
357
358 hres = IAccessible_QueryInterface(&window->IAccessible_iface, iid, obj);
359 IAccessible_Release(&window->IAccessible_iface);
360 return hres;
361 }