user32/tests: Test pending redraw state with owner-drawn list box.
[wine.git] / dlls / hlink / browse_ctx.c
blob3fe6885422c0b735a2dbb8387fc2701920531d34
1 /*
2 * Implementation of hyperlinking (hlink.dll)
4 * Copyright 2005 Aric Stewart 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 "hlink_private.h"
23 #include "wine/debug.h"
24 #include "wine/list.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(hlink);
28 struct link_entry
30 struct list entry;
31 IHlink *link;
34 typedef struct
36 IHlinkBrowseContext IHlinkBrowseContext_iface;
37 LONG ref;
38 HLBWINFO* BrowseWindowInfo;
39 struct link_entry *current;
40 struct list links;
41 } HlinkBCImpl;
43 static inline HlinkBCImpl *impl_from_IHlinkBrowseContext(IHlinkBrowseContext *iface)
45 return CONTAINING_RECORD(iface, HlinkBCImpl, IHlinkBrowseContext_iface);
48 static HRESULT WINAPI IHlinkBC_fnQueryInterface( IHlinkBrowseContext *iface,
49 REFIID riid, LPVOID* ppvObj)
51 HlinkBCImpl *This = impl_from_IHlinkBrowseContext(iface);
52 TRACE ("(%p)->(%s,%p)\n", This, debugstr_guid (riid), ppvObj);
54 if (IsEqualIID(riid, &IID_IUnknown) ||
55 IsEqualIID(riid, &IID_IHlinkBrowseContext))
56 *ppvObj = This;
58 if (*ppvObj)
60 IUnknown_AddRef((IUnknown*)(*ppvObj));
61 return S_OK;
63 return E_NOINTERFACE;
66 static ULONG WINAPI IHlinkBC_fnAddRef (IHlinkBrowseContext* iface)
68 HlinkBCImpl *This = impl_from_IHlinkBrowseContext(iface);
69 ULONG refCount = InterlockedIncrement(&This->ref);
71 TRACE("(%p)->(count=%u)\n", This, refCount - 1);
73 return refCount;
76 static ULONG WINAPI IHlinkBC_fnRelease (IHlinkBrowseContext* iface)
78 HlinkBCImpl *This = impl_from_IHlinkBrowseContext(iface);
79 ULONG ref = InterlockedDecrement(&This->ref);
81 TRACE("(%p)->(count=%u)\n", This, ref + 1);
83 if (!ref)
85 struct link_entry *link, *link2;
87 LIST_FOR_EACH_ENTRY_SAFE(link, link2, &This->links, struct link_entry, entry)
89 list_remove(&link->entry);
90 IHlink_Release(link->link);
91 heap_free(link);
94 heap_free(This->BrowseWindowInfo);
95 heap_free(This);
98 return ref;
101 static HRESULT WINAPI IHlinkBC_Register(IHlinkBrowseContext* iface,
102 DWORD dwReserved, IUnknown *piunk, IMoniker *pimk, DWORD *pdwRegister)
104 HlinkBCImpl *This = impl_from_IHlinkBrowseContext(iface);
105 IMoniker *mon;
106 IMoniker *composite;
107 IRunningObjectTable *ROT;
108 HRESULT hr;
110 FIXME("(%p)->(%i %p %p %p)\n", This, dwReserved, piunk, pimk, pdwRegister);
112 hr = CreateItemMoniker(NULL, L"WINEHLINK", &mon);
113 if (FAILED(hr))
114 return hr;
115 CreateGenericComposite(mon, pimk, &composite);
117 GetRunningObjectTable(0, &ROT);
118 IRunningObjectTable_Register(ROT, 0, piunk, composite, pdwRegister);
120 IRunningObjectTable_Release(ROT);
121 IMoniker_Release(composite);
122 IMoniker_Release(mon);
124 return S_OK;
127 static HRESULT WINAPI IHlinkBC_GetObject(IHlinkBrowseContext* iface,
128 IMoniker *pimk, BOOL fBindifRootRegistered, IUnknown **ppiunk)
130 HlinkBCImpl *This = impl_from_IHlinkBrowseContext(iface);
131 IMoniker *mon;
132 IMoniker *composite;
133 IRunningObjectTable *ROT;
134 HRESULT hr;
136 TRACE("(%p)->(%p, %d, %p)\n", This, pimk, fBindifRootRegistered, ppiunk);
138 hr = CreateItemMoniker(NULL, L"WINEHLINK", &mon);
139 if (FAILED(hr)) return hr;
140 CreateGenericComposite(mon, pimk, &composite);
142 GetRunningObjectTable(0, &ROT);
143 hr = IRunningObjectTable_GetObject(ROT, composite, ppiunk);
145 IRunningObjectTable_Release(ROT);
146 IMoniker_Release(composite);
147 IMoniker_Release(mon);
149 return hr;
152 static HRESULT WINAPI IHlinkBC_Revoke(IHlinkBrowseContext* iface,
153 DWORD dwRegister)
155 HRESULT r;
156 IRunningObjectTable *ROT;
157 HlinkBCImpl *This = impl_from_IHlinkBrowseContext(iface);
159 FIXME("(%p)->(%i)\n", This, dwRegister);
161 GetRunningObjectTable(0, &ROT);
162 r = IRunningObjectTable_Revoke(ROT, dwRegister);
163 IRunningObjectTable_Release(ROT);
165 return r;
168 static HRESULT WINAPI IHlinkBC_SetBrowseWindowInfo(IHlinkBrowseContext* iface,
169 HLBWINFO *phlbwi)
171 HlinkBCImpl *This = impl_from_IHlinkBrowseContext(iface);
172 TRACE("(%p)->(%p)\n", This, phlbwi);
174 if(!phlbwi)
175 return E_INVALIDARG;
177 heap_free(This->BrowseWindowInfo);
178 This->BrowseWindowInfo = heap_alloc(phlbwi->cbSize);
179 memcpy(This->BrowseWindowInfo, phlbwi, phlbwi->cbSize);
181 return S_OK;
184 static HRESULT WINAPI IHlinkBC_GetBrowseWindowInfo(IHlinkBrowseContext* iface,
185 HLBWINFO *phlbwi)
187 HlinkBCImpl *This = impl_from_IHlinkBrowseContext(iface);
188 TRACE("(%p)->(%p)\n", This, phlbwi);
190 if(!phlbwi)
191 return E_INVALIDARG;
193 if(!This->BrowseWindowInfo)
194 phlbwi->cbSize = 0;
195 else
196 memcpy(phlbwi, This->BrowseWindowInfo, This->BrowseWindowInfo->cbSize);
198 return S_OK;
201 static HRESULT WINAPI IHlinkBC_SetInitialHlink(IHlinkBrowseContext* iface,
202 IMoniker *pimkTarget, LPCWSTR pwzLocation, LPCWSTR pwzFriendlyName)
204 HlinkBCImpl *This = impl_from_IHlinkBrowseContext(iface);
205 struct link_entry *link;
207 TRACE("(%p)->(%p %s %s)\n", This, pimkTarget, debugstr_w(pwzLocation), debugstr_w(pwzFriendlyName));
209 if (!list_empty(&This->links))
210 return CO_E_ALREADYINITIALIZED;
212 link = heap_alloc(sizeof(struct link_entry));
213 if (!link) return E_OUTOFMEMORY;
215 HlinkCreateFromMoniker(pimkTarget, pwzLocation, pwzFriendlyName, NULL,
216 0, NULL, &IID_IHlink, (void**)&link->link);
218 list_add_head(&This->links, &link->entry);
219 This->current = LIST_ENTRY(list_head(&This->links), struct link_entry, entry);
220 return S_OK;
223 static HRESULT WINAPI IHlinkBC_OnNavigateHlink(IHlinkBrowseContext *iface,
224 DWORD grfHLNF, IMoniker* pmkTarget, LPCWSTR pwzLocation, LPCWSTR
225 pwzFriendlyName, ULONG *puHLID)
227 HlinkBCImpl *This = impl_from_IHlinkBrowseContext(iface);
229 FIXME("(%p)->(%i %p %s %s %p)\n", This, grfHLNF, pmkTarget,
230 debugstr_w(pwzLocation), debugstr_w(pwzFriendlyName), puHLID);
232 return S_OK;
235 static struct link_entry *context_get_entry(HlinkBCImpl *ctxt, ULONG hlid)
237 struct list *entry;
239 switch (hlid)
241 case HLID_PREVIOUS:
242 entry = list_prev(&ctxt->links, &ctxt->current->entry);
243 break;
244 case HLID_NEXT:
245 entry = list_next(&ctxt->links, &ctxt->current->entry);
246 break;
247 case HLID_CURRENT:
248 entry = &ctxt->current->entry;
249 break;
250 case HLID_STACKBOTTOM:
251 entry = list_tail(&ctxt->links);
252 break;
253 case HLID_STACKTOP:
254 entry = list_head(&ctxt->links);
255 break;
256 default:
257 WARN("unknown id 0x%x\n", hlid);
258 entry = NULL;
261 return entry ? LIST_ENTRY(entry, struct link_entry, entry) : NULL;
264 static HRESULT WINAPI IHlinkBC_UpdateHlink(IHlinkBrowseContext* iface,
265 ULONG hlid, IMoniker *target, LPCWSTR location, LPCWSTR friendly_name)
267 HlinkBCImpl *This = impl_from_IHlinkBrowseContext(iface);
268 struct link_entry *entry = context_get_entry(This, hlid);
269 IHlink *link;
270 HRESULT hr;
272 TRACE("(%p)->(0x%x %p %s %s)\n", This, hlid, target, debugstr_w(location), debugstr_w(friendly_name));
274 if (!entry)
275 return E_INVALIDARG;
277 hr = HlinkCreateFromMoniker(target, location, friendly_name, NULL, 0, NULL, &IID_IHlink, (void**)&link);
278 if (FAILED(hr))
279 return hr;
281 IHlink_Release(entry->link);
282 entry->link = link;
284 return S_OK;
287 static HRESULT WINAPI IHlinkBC_EnumNavigationStack( IHlinkBrowseContext *iface,
288 DWORD dwReserved, DWORD grfHLFNAMEF, IEnumHLITEM** ppienumhlitem)
290 FIXME("\n");
291 return E_NOTIMPL;
294 static HRESULT WINAPI IHlinkBC_QueryHlink( IHlinkBrowseContext* iface,
295 DWORD grfHLONG, ULONG uHLID)
297 FIXME("\n");
298 return E_NOTIMPL;
301 static HRESULT WINAPI IHlinkBC_GetHlink(IHlinkBrowseContext* iface, ULONG hlid, IHlink **ret)
303 HlinkBCImpl *This = impl_from_IHlinkBrowseContext(iface);
304 struct link_entry *link;
306 TRACE("(%p)->(0x%x %p)\n", This, hlid, ret);
308 link = context_get_entry(This, hlid);
309 if (!link)
310 return E_FAIL;
312 *ret = link->link;
313 IHlink_AddRef(*ret);
315 return S_OK;
318 static HRESULT WINAPI IHlinkBC_SetCurrentHlink(IHlinkBrowseContext* iface, ULONG hlid)
320 HlinkBCImpl *This = impl_from_IHlinkBrowseContext(iface);
321 struct link_entry *link;
323 TRACE("(%p)->(0x%08x)\n", This, hlid);
325 link = context_get_entry(This, hlid);
326 if (!link)
327 return E_FAIL;
329 This->current = link;
330 return S_OK;
333 static HRESULT WINAPI IHlinkBC_Clone( IHlinkBrowseContext* iface,
334 IUnknown* piunkOuter, REFIID riid, IUnknown** ppiunkOjb)
336 FIXME("\n");
337 return E_NOTIMPL;
340 static HRESULT WINAPI IHlinkBC_Close(IHlinkBrowseContext* iface,
341 DWORD reserved)
343 FIXME("\n");
344 return E_NOTIMPL;
347 static const IHlinkBrowseContextVtbl hlvt =
349 IHlinkBC_fnQueryInterface,
350 IHlinkBC_fnAddRef,
351 IHlinkBC_fnRelease,
352 IHlinkBC_Register,
353 IHlinkBC_GetObject,
354 IHlinkBC_Revoke,
355 IHlinkBC_SetBrowseWindowInfo,
356 IHlinkBC_GetBrowseWindowInfo,
357 IHlinkBC_SetInitialHlink,
358 IHlinkBC_OnNavigateHlink,
359 IHlinkBC_UpdateHlink,
360 IHlinkBC_EnumNavigationStack,
361 IHlinkBC_QueryHlink,
362 IHlinkBC_GetHlink,
363 IHlinkBC_SetCurrentHlink,
364 IHlinkBC_Clone,
365 IHlinkBC_Close
368 HRESULT HLinkBrowseContext_Constructor(IUnknown *pUnkOuter, REFIID riid, void **ppv)
370 HlinkBCImpl * hl;
372 TRACE("unkOut=%p riid=%s\n", pUnkOuter, debugstr_guid(riid));
373 *ppv = NULL;
375 if (pUnkOuter)
376 return CLASS_E_NOAGGREGATION;
378 hl = heap_alloc_zero(sizeof(HlinkBCImpl));
379 if (!hl)
380 return E_OUTOFMEMORY;
382 hl->ref = 1;
383 hl->IHlinkBrowseContext_iface.lpVtbl = &hlvt;
384 list_init(&hl->links);
385 hl->current = NULL;
387 *ppv = hl;
388 return S_OK;