2006-06-06 12:39:58 +02:00
|
|
|
/*
|
|
|
|
* Implementation of hyperlinking (hlink.dll)
|
|
|
|
*
|
|
|
|
* Copyright 2005 Aric Stewart for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2007-11-21 02:13:36 +01:00
|
|
|
#include "hlink_private.h"
|
2006-06-06 12:39:58 +02:00
|
|
|
|
|
|
|
#include "wine/debug.h"
|
2013-03-23 19:29:07 +01:00
|
|
|
#include "wine/list.h"
|
2006-06-06 12:39:58 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(hlink);
|
|
|
|
|
2013-03-23 19:29:07 +01:00
|
|
|
struct link_entry
|
|
|
|
{
|
|
|
|
struct list entry;
|
|
|
|
IHlink *link;
|
|
|
|
};
|
|
|
|
|
2006-06-06 12:39:58 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
2010-12-04 22:13:41 +01:00
|
|
|
IHlinkBrowseContext IHlinkBrowseContext_iface;
|
2006-06-06 12:39:58 +02:00
|
|
|
LONG ref;
|
|
|
|
HLBWINFO* BrowseWindowInfo;
|
2013-03-23 19:29:07 +01:00
|
|
|
struct link_entry *current;
|
|
|
|
struct list links;
|
2006-06-06 12:39:58 +02:00
|
|
|
} HlinkBCImpl;
|
|
|
|
|
2010-12-04 22:13:41 +01:00
|
|
|
static inline HlinkBCImpl *impl_from_IHlinkBrowseContext(IHlinkBrowseContext *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, HlinkBCImpl, IHlinkBrowseContext_iface);
|
|
|
|
}
|
|
|
|
|
2006-06-06 12:39:58 +02:00
|
|
|
static HRESULT WINAPI IHlinkBC_fnQueryInterface( IHlinkBrowseContext *iface,
|
|
|
|
REFIID riid, LPVOID* ppvObj)
|
|
|
|
{
|
2010-12-04 22:13:41 +01:00
|
|
|
HlinkBCImpl *This = impl_from_IHlinkBrowseContext(iface);
|
2006-06-06 12:39:58 +02:00
|
|
|
TRACE ("(%p)->(%s,%p)\n", This, debugstr_guid (riid), ppvObj);
|
|
|
|
|
|
|
|
if (IsEqualIID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualIID(riid, &IID_IHlinkBrowseContext))
|
|
|
|
*ppvObj = This;
|
|
|
|
|
|
|
|
if (*ppvObj)
|
|
|
|
{
|
|
|
|
IUnknown_AddRef((IUnknown*)(*ppvObj));
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI IHlinkBC_fnAddRef (IHlinkBrowseContext* iface)
|
|
|
|
{
|
2010-12-04 22:13:41 +01:00
|
|
|
HlinkBCImpl *This = impl_from_IHlinkBrowseContext(iface);
|
2006-06-06 12:39:58 +02:00
|
|
|
ULONG refCount = InterlockedIncrement(&This->ref);
|
|
|
|
|
2022-02-10 08:43:37 +01:00
|
|
|
TRACE("(%p)->(count=%lu)\n", This, refCount - 1);
|
2006-06-06 12:39:58 +02:00
|
|
|
|
|
|
|
return refCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI IHlinkBC_fnRelease (IHlinkBrowseContext* iface)
|
|
|
|
{
|
2010-12-04 22:13:41 +01:00
|
|
|
HlinkBCImpl *This = impl_from_IHlinkBrowseContext(iface);
|
2013-03-23 19:29:07 +01:00
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
2006-06-06 12:39:58 +02:00
|
|
|
|
2022-02-10 08:43:37 +01:00
|
|
|
TRACE("(%p)->(count=%lu)\n", This, ref + 1);
|
2006-06-06 12:39:58 +02:00
|
|
|
|
2013-03-23 19:29:07 +01:00
|
|
|
if (!ref)
|
|
|
|
{
|
|
|
|
struct link_entry *link, *link2;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(link, link2, &This->links, struct link_entry, entry)
|
|
|
|
{
|
|
|
|
list_remove(&link->entry);
|
|
|
|
IHlink_Release(link->link);
|
|
|
|
heap_free(link);
|
|
|
|
}
|
|
|
|
|
|
|
|
heap_free(This->BrowseWindowInfo);
|
|
|
|
heap_free(This);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
2006-06-06 12:39:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IHlinkBC_Register(IHlinkBrowseContext* iface,
|
|
|
|
DWORD dwReserved, IUnknown *piunk, IMoniker *pimk, DWORD *pdwRegister)
|
|
|
|
{
|
2010-12-04 22:13:41 +01:00
|
|
|
HlinkBCImpl *This = impl_from_IHlinkBrowseContext(iface);
|
2006-06-06 12:39:58 +02:00
|
|
|
IMoniker *mon;
|
|
|
|
IMoniker *composite;
|
|
|
|
IRunningObjectTable *ROT;
|
2016-08-04 10:08:26 +02:00
|
|
|
HRESULT hr;
|
2006-06-06 12:39:58 +02:00
|
|
|
|
2022-02-10 08:43:37 +01:00
|
|
|
FIXME("(%p)->(%li %p %p %p)\n", This, dwReserved, piunk, pimk, pdwRegister);
|
2006-06-06 12:39:58 +02:00
|
|
|
|
2020-10-03 20:28:12 +02:00
|
|
|
hr = CreateItemMoniker(NULL, L"WINEHLINK", &mon);
|
2016-08-04 10:08:26 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
2006-06-06 12:39:58 +02:00
|
|
|
CreateGenericComposite(mon, pimk, &composite);
|
|
|
|
|
|
|
|
GetRunningObjectTable(0, &ROT);
|
|
|
|
IRunningObjectTable_Register(ROT, 0, piunk, composite, pdwRegister);
|
|
|
|
|
|
|
|
IRunningObjectTable_Release(ROT);
|
|
|
|
IMoniker_Release(composite);
|
|
|
|
IMoniker_Release(mon);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2018-01-10 03:59:39 +01:00
|
|
|
static HRESULT WINAPI IHlinkBC_GetObject(IHlinkBrowseContext* iface,
|
2006-06-06 12:39:58 +02:00
|
|
|
IMoniker *pimk, BOOL fBindifRootRegistered, IUnknown **ppiunk)
|
|
|
|
{
|
2018-01-10 03:59:39 +01:00
|
|
|
HlinkBCImpl *This = impl_from_IHlinkBrowseContext(iface);
|
|
|
|
IMoniker *mon;
|
|
|
|
IMoniker *composite;
|
|
|
|
IRunningObjectTable *ROT;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p, %d, %p)\n", This, pimk, fBindifRootRegistered, ppiunk);
|
|
|
|
|
2020-10-03 20:28:12 +02:00
|
|
|
hr = CreateItemMoniker(NULL, L"WINEHLINK", &mon);
|
2018-01-10 03:59:39 +01:00
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
CreateGenericComposite(mon, pimk, &composite);
|
|
|
|
|
|
|
|
GetRunningObjectTable(0, &ROT);
|
|
|
|
hr = IRunningObjectTable_GetObject(ROT, composite, ppiunk);
|
|
|
|
|
|
|
|
IRunningObjectTable_Release(ROT);
|
|
|
|
IMoniker_Release(composite);
|
|
|
|
IMoniker_Release(mon);
|
|
|
|
|
|
|
|
return hr;
|
2006-06-06 12:39:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IHlinkBC_Revoke(IHlinkBrowseContext* iface,
|
|
|
|
DWORD dwRegister)
|
|
|
|
{
|
2013-03-23 18:53:14 +01:00
|
|
|
HRESULT r;
|
2006-06-06 12:39:58 +02:00
|
|
|
IRunningObjectTable *ROT;
|
2010-12-04 22:13:41 +01:00
|
|
|
HlinkBCImpl *This = impl_from_IHlinkBrowseContext(iface);
|
2006-06-06 12:39:58 +02:00
|
|
|
|
2022-02-10 08:43:37 +01:00
|
|
|
FIXME("(%p)->(%li)\n", This, dwRegister);
|
2006-06-06 12:39:58 +02:00
|
|
|
|
|
|
|
GetRunningObjectTable(0, &ROT);
|
|
|
|
r = IRunningObjectTable_Revoke(ROT, dwRegister);
|
|
|
|
IRunningObjectTable_Release(ROT);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IHlinkBC_SetBrowseWindowInfo(IHlinkBrowseContext* iface,
|
|
|
|
HLBWINFO *phlbwi)
|
|
|
|
{
|
2010-12-04 22:13:41 +01:00
|
|
|
HlinkBCImpl *This = impl_from_IHlinkBrowseContext(iface);
|
2006-06-06 12:39:58 +02:00
|
|
|
TRACE("(%p)->(%p)\n", This, phlbwi);
|
|
|
|
|
2010-03-16 22:49:23 +01:00
|
|
|
if(!phlbwi)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2007-12-09 16:29:51 +01:00
|
|
|
heap_free(This->BrowseWindowInfo);
|
|
|
|
This->BrowseWindowInfo = heap_alloc(phlbwi->cbSize);
|
2006-06-06 12:39:58 +02:00
|
|
|
memcpy(This->BrowseWindowInfo, phlbwi, phlbwi->cbSize);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IHlinkBC_GetBrowseWindowInfo(IHlinkBrowseContext* iface,
|
|
|
|
HLBWINFO *phlbwi)
|
|
|
|
{
|
2010-12-04 22:13:41 +01:00
|
|
|
HlinkBCImpl *This = impl_from_IHlinkBrowseContext(iface);
|
2010-03-16 22:49:23 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, phlbwi);
|
|
|
|
|
|
|
|
if(!phlbwi)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if(!This->BrowseWindowInfo)
|
|
|
|
phlbwi->cbSize = 0;
|
|
|
|
else
|
|
|
|
memcpy(phlbwi, This->BrowseWindowInfo, This->BrowseWindowInfo->cbSize);
|
|
|
|
|
|
|
|
return S_OK;
|
2006-06-06 12:39:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IHlinkBC_SetInitialHlink(IHlinkBrowseContext* iface,
|
|
|
|
IMoniker *pimkTarget, LPCWSTR pwzLocation, LPCWSTR pwzFriendlyName)
|
|
|
|
{
|
2013-03-23 19:29:07 +01:00
|
|
|
HlinkBCImpl *This = impl_from_IHlinkBrowseContext(iface);
|
|
|
|
struct link_entry *link;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p %s %s)\n", This, pimkTarget, debugstr_w(pwzLocation), debugstr_w(pwzFriendlyName));
|
2006-06-06 12:39:58 +02:00
|
|
|
|
2013-03-23 19:29:07 +01:00
|
|
|
if (!list_empty(&This->links))
|
|
|
|
return CO_E_ALREADYINITIALIZED;
|
2006-06-06 12:39:58 +02:00
|
|
|
|
2013-03-23 19:29:07 +01:00
|
|
|
link = heap_alloc(sizeof(struct link_entry));
|
|
|
|
if (!link) return E_OUTOFMEMORY;
|
2006-06-06 12:39:58 +02:00
|
|
|
|
|
|
|
HlinkCreateFromMoniker(pimkTarget, pwzLocation, pwzFriendlyName, NULL,
|
2013-03-23 19:29:07 +01:00
|
|
|
0, NULL, &IID_IHlink, (void**)&link->link);
|
2006-06-06 12:39:58 +02:00
|
|
|
|
2013-03-23 19:29:07 +01:00
|
|
|
list_add_head(&This->links, &link->entry);
|
|
|
|
This->current = LIST_ENTRY(list_head(&This->links), struct link_entry, entry);
|
2006-06-06 12:39:58 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IHlinkBC_OnNavigateHlink(IHlinkBrowseContext *iface,
|
|
|
|
DWORD grfHLNF, IMoniker* pmkTarget, LPCWSTR pwzLocation, LPCWSTR
|
|
|
|
pwzFriendlyName, ULONG *puHLID)
|
|
|
|
{
|
2010-12-04 22:13:41 +01:00
|
|
|
HlinkBCImpl *This = impl_from_IHlinkBrowseContext(iface);
|
2006-06-06 12:39:58 +02:00
|
|
|
|
2022-02-10 08:43:37 +01:00
|
|
|
FIXME("(%p)->(%li %p %s %s %p)\n", This, grfHLNF, pmkTarget,
|
2006-06-06 12:39:58 +02:00
|
|
|
debugstr_w(pwzLocation), debugstr_w(pwzFriendlyName), puHLID);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2013-03-25 14:50:32 +01:00
|
|
|
static struct link_entry *context_get_entry(HlinkBCImpl *ctxt, ULONG hlid)
|
|
|
|
{
|
|
|
|
struct list *entry;
|
|
|
|
|
|
|
|
switch (hlid)
|
|
|
|
{
|
|
|
|
case HLID_PREVIOUS:
|
|
|
|
entry = list_prev(&ctxt->links, &ctxt->current->entry);
|
|
|
|
break;
|
|
|
|
case HLID_NEXT:
|
|
|
|
entry = list_next(&ctxt->links, &ctxt->current->entry);
|
|
|
|
break;
|
|
|
|
case HLID_CURRENT:
|
|
|
|
entry = &ctxt->current->entry;
|
|
|
|
break;
|
|
|
|
case HLID_STACKBOTTOM:
|
|
|
|
entry = list_tail(&ctxt->links);
|
|
|
|
break;
|
|
|
|
case HLID_STACKTOP:
|
|
|
|
entry = list_head(&ctxt->links);
|
|
|
|
break;
|
|
|
|
default:
|
2022-02-10 08:43:37 +01:00
|
|
|
WARN("unknown id 0x%lx\n", hlid);
|
2013-03-25 14:50:32 +01:00
|
|
|
entry = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return entry ? LIST_ENTRY(entry, struct link_entry, entry) : NULL;
|
|
|
|
}
|
|
|
|
|
2006-06-06 12:39:58 +02:00
|
|
|
static HRESULT WINAPI IHlinkBC_UpdateHlink(IHlinkBrowseContext* iface,
|
2013-03-25 14:50:32 +01:00
|
|
|
ULONG hlid, IMoniker *target, LPCWSTR location, LPCWSTR friendly_name)
|
2006-06-06 12:39:58 +02:00
|
|
|
{
|
2013-03-25 14:50:32 +01:00
|
|
|
HlinkBCImpl *This = impl_from_IHlinkBrowseContext(iface);
|
|
|
|
struct link_entry *entry = context_get_entry(This, hlid);
|
|
|
|
IHlink *link;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2022-02-10 08:43:37 +01:00
|
|
|
TRACE("(%p)->(0x%lx %p %s %s)\n", This, hlid, target, debugstr_w(location), debugstr_w(friendly_name));
|
2013-03-25 14:50:32 +01:00
|
|
|
|
|
|
|
if (!entry)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
hr = HlinkCreateFromMoniker(target, location, friendly_name, NULL, 0, NULL, &IID_IHlink, (void**)&link);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
IHlink_Release(entry->link);
|
|
|
|
entry->link = link;
|
|
|
|
|
|
|
|
return S_OK;
|
2006-06-06 12:39:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IHlinkBC_EnumNavigationStack( IHlinkBrowseContext *iface,
|
|
|
|
DWORD dwReserved, DWORD grfHLFNAMEF, IEnumHLITEM** ppienumhlitem)
|
|
|
|
{
|
|
|
|
FIXME("\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IHlinkBC_QueryHlink( IHlinkBrowseContext* iface,
|
|
|
|
DWORD grfHLONG, ULONG uHLID)
|
|
|
|
{
|
|
|
|
FIXME("\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2013-03-25 14:44:31 +01:00
|
|
|
static HRESULT WINAPI IHlinkBC_GetHlink(IHlinkBrowseContext* iface, ULONG hlid, IHlink **ret)
|
2006-06-06 12:39:58 +02:00
|
|
|
{
|
2013-03-25 14:44:31 +01:00
|
|
|
HlinkBCImpl *This = impl_from_IHlinkBrowseContext(iface);
|
|
|
|
struct link_entry *link;
|
2009-12-23 00:43:29 +01:00
|
|
|
|
2022-02-10 08:43:37 +01:00
|
|
|
TRACE("(%p)->(0x%lx %p)\n", This, hlid, ret);
|
2009-12-23 00:43:29 +01:00
|
|
|
|
2013-03-25 14:50:32 +01:00
|
|
|
link = context_get_entry(This, hlid);
|
|
|
|
if (!link)
|
2013-03-25 14:44:31 +01:00
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
*ret = link->link;
|
|
|
|
IHlink_AddRef(*ret);
|
2009-12-23 00:43:29 +01:00
|
|
|
|
|
|
|
return S_OK;
|
2006-06-06 12:39:58 +02:00
|
|
|
}
|
|
|
|
|
2013-03-27 07:41:07 +01:00
|
|
|
static HRESULT WINAPI IHlinkBC_SetCurrentHlink(IHlinkBrowseContext* iface, ULONG hlid)
|
2006-06-06 12:39:58 +02:00
|
|
|
{
|
2013-03-27 07:41:07 +01:00
|
|
|
HlinkBCImpl *This = impl_from_IHlinkBrowseContext(iface);
|
|
|
|
struct link_entry *link;
|
|
|
|
|
2022-02-10 08:43:37 +01:00
|
|
|
TRACE("(%p)->(0x%08lx)\n", This, hlid);
|
2013-03-27 07:41:07 +01:00
|
|
|
|
|
|
|
link = context_get_entry(This, hlid);
|
|
|
|
if (!link)
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
This->current = link;
|
|
|
|
return S_OK;
|
2006-06-06 12:39:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IHlinkBC_Clone( IHlinkBrowseContext* iface,
|
|
|
|
IUnknown* piunkOuter, REFIID riid, IUnknown** ppiunkOjb)
|
|
|
|
{
|
|
|
|
FIXME("\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IHlinkBC_Close(IHlinkBrowseContext* iface,
|
2011-08-03 11:36:46 +02:00
|
|
|
DWORD reserved)
|
2006-06-06 12:39:58 +02:00
|
|
|
{
|
|
|
|
FIXME("\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IHlinkBrowseContextVtbl hlvt =
|
|
|
|
{
|
|
|
|
IHlinkBC_fnQueryInterface,
|
|
|
|
IHlinkBC_fnAddRef,
|
|
|
|
IHlinkBC_fnRelease,
|
|
|
|
IHlinkBC_Register,
|
|
|
|
IHlinkBC_GetObject,
|
|
|
|
IHlinkBC_Revoke,
|
|
|
|
IHlinkBC_SetBrowseWindowInfo,
|
|
|
|
IHlinkBC_GetBrowseWindowInfo,
|
|
|
|
IHlinkBC_SetInitialHlink,
|
|
|
|
IHlinkBC_OnNavigateHlink,
|
|
|
|
IHlinkBC_UpdateHlink,
|
|
|
|
IHlinkBC_EnumNavigationStack,
|
|
|
|
IHlinkBC_QueryHlink,
|
|
|
|
IHlinkBC_GetHlink,
|
|
|
|
IHlinkBC_SetCurrentHlink,
|
|
|
|
IHlinkBC_Clone,
|
|
|
|
IHlinkBC_Close
|
|
|
|
};
|
2011-10-21 15:12:21 +02:00
|
|
|
|
|
|
|
HRESULT HLinkBrowseContext_Constructor(IUnknown *pUnkOuter, REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
HlinkBCImpl * hl;
|
|
|
|
|
|
|
|
TRACE("unkOut=%p riid=%s\n", pUnkOuter, debugstr_guid(riid));
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
if (pUnkOuter)
|
|
|
|
return CLASS_E_NOAGGREGATION;
|
|
|
|
|
|
|
|
hl = heap_alloc_zero(sizeof(HlinkBCImpl));
|
|
|
|
if (!hl)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
hl->ref = 1;
|
|
|
|
hl->IHlinkBrowseContext_iface.lpVtbl = &hlvt;
|
2013-03-23 19:29:07 +01:00
|
|
|
list_init(&hl->links);
|
|
|
|
hl->current = NULL;
|
2011-10-21 15:12:21 +02:00
|
|
|
|
|
|
|
*ppv = hl;
|
|
|
|
return S_OK;
|
|
|
|
}
|