📄 tbsite.c
字号:
/*
* ReactOS Explorer
*
* Copyright 2006 - 2007 Thomas Weidenmueller <w3seek@reactos.org>
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <precomp.h>
/*****************************************************************************
** ITrayBandSite ************************************************************
*****************************************************************************/
static const ITrayBandSiteVtbl ITrayBandSiteImpl_Vtbl;
static const IBandSiteVtbl IBandSiteImpl_Vtbl;
typedef struct
{
const ITrayBandSiteVtbl *lpVtbl;
const IBandSiteVtbl *lpBandSiteVtbl;
LONG Ref;
ITrayWindow *Tray;
IUnknown *punkInner;
IBandSite *BandSite;
ITaskBand *TaskBand;
IWindowEventHandler *WindowEventHandler;
IContextMenu *ContextMenu;
HWND hWndRebar;
union
{
DWORD dwFlags;
struct
{
DWORD Locked : 1;
};
};
} ITrayBandSiteImpl;
static HRESULT
ITrayBandSiteImpl_Update(IN OUT ITrayBandSiteImpl *This);
static IUnknown *
IUnknown_from_ITrayBandSiteImpl(ITrayBandSiteImpl *This)
{
return (IUnknown *)&This->lpVtbl;
}
IMPL_CASTS(ITrayBandSite, ITrayBandSite, lpVtbl)
IMPL_CASTS(IBandSite, ITrayBandSite, lpBandSiteVtbl)
static ULONG STDMETHODCALLTYPE
ITrayBandSiteImpl_AddRef(IN OUT ITrayBandSite *iface)
{
ITrayBandSiteImpl *This = ITrayBandSiteImpl_from_ITrayBandSite(iface);
return InterlockedIncrement(&This->Ref);
}
static VOID
ITrayBandSiteImpl_Free(IN OUT ITrayBandSiteImpl *This)
{
if (This->BandSite != NULL)
{
IBandSite_Release(This->BandSite);
This->BandSite = NULL;
}
if (This->WindowEventHandler != NULL)
{
IWindowEventHandler_Release(This->WindowEventHandler);
This->WindowEventHandler = NULL;
}
if (This->ContextMenu != NULL)
{
IContextMenu_Release(This->ContextMenu);
This->ContextMenu = NULL;
}
if (This->punkInner != NULL)
{
IUnknown_Release(This->punkInner);
This->punkInner = NULL;
}
HeapFree(hProcessHeap,
0,
This);
}
static ULONG STDMETHODCALLTYPE
ITrayBandSiteImpl_Release(IN OUT ITrayBandSite *iface)
{
ITrayBandSiteImpl *This = ITrayBandSiteImpl_from_ITrayBandSite(iface);
ULONG Ret;
Ret = InterlockedDecrement(&This->Ref);
if (Ret == 0)
ITrayBandSiteImpl_Free(This);
return Ret;
}
static HRESULT STDMETHODCALLTYPE
ITrayBandSiteImpl_QueryInterface(IN OUT ITrayBandSite *iface,
IN REFIID riid,
OUT LPVOID *ppvObj)
{
ITrayBandSiteImpl *This;
if (ppvObj == NULL)
return E_POINTER;
This = ITrayBandSiteImpl_from_ITrayBandSite(iface);
if (IsEqualIID(riid,
&IID_IUnknown) ||
IsEqualIID(riid,
&IID_IBandSiteStreamCallback))
{
/* NOTE: IID_IBandSiteStreamCallback is queried by the shell, we
implement this interface directly */
*ppvObj = IUnknown_from_ITrayBandSiteImpl(This);
}
else if (IsEqualIID(riid,
&IID_IBandSite))
{
*ppvObj = IBandSite_from_ITrayBandSiteImpl(This);
}
else if (IsEqualIID(riid,
&IID_IWindowEventHandler))
{
DbgPrint("ITaskBandSite: IWindowEventHandler queried!\n");
*ppvObj = NULL;
return E_NOINTERFACE;
}
else if (This->punkInner != NULL)
{
return IUnknown_QueryInterface(This->punkInner,
riid,
ppvObj);
}
else
{
*ppvObj = NULL;
return E_NOINTERFACE;
}
ITrayBandSiteImpl_AddRef(iface);
return S_OK;
}
static HRESULT STDMETHODCALLTYPE
ITrayBandSiteImpl_OnLoad(IN OUT ITrayBandSite *iface,
IN OUT IStream *pStm,
IN REFIID riid,
OUT PVOID *pvObj)
{
ITrayBandSiteImpl *This = ITrayBandSiteImpl_from_ITrayBandSite(iface);
LARGE_INTEGER liPosZero;
ULARGE_INTEGER liCurrent;
CLSID clsid;
ULONG ulRead;
HRESULT hRet;
/* NOTE: Callback routine called by the shell while loading the task band
stream. We use it to intercept the default behavior when the task
band is loaded from the stream.
NOTE: riid always points to IID_IUnknown! This is because the shell hasn't
read anything from the stream and therefore doesn't know what CLSID
it's dealing with. We'll have to find it out ourselves by reading
the GUID from the stream. */
/* Read the current position of the stream, we'll have to reset it everytime
we read a CLSID that's not the task band... */
ZeroMemory(&liPosZero,
sizeof(liPosZero));
hRet = IStream_Seek(pStm,
liPosZero,
STREAM_SEEK_CUR,
&liCurrent);
if (SUCCEEDED(hRet))
{
/* Now let's read the CLSID from the stream and see if it's our task band */
hRet = IStream_Read(pStm,
&clsid,
sizeof(clsid),
&ulRead);
if (SUCCEEDED(hRet) && ulRead == sizeof(clsid))
{
if (IsEqualGUID(&clsid,
&CLSID_ITaskBand))
{
ASSERT(This->TaskBand != NULL);
/* We're trying to load the task band! Let's create it... */
hRet = ITaskBand_QueryInterface(This->TaskBand,
riid,
pvObj);
if (SUCCEEDED(hRet))
{
/* Load the stream */
DbgPrint("IBandSiteStreamCallback::OnLoad intercepted the task band CLSID!\n");
}
return hRet;
}
}
}
/* Reset the position and let the shell do all the work for us */
hRet = IStream_Seek(pStm,
*(LARGE_INTEGER*)&liCurrent,
STREAM_SEEK_SET,
NULL);
if (SUCCEEDED(hRet))
{
/* Let the shell handle everything else for us :) */
hRet = OleLoadFromStream(pStm,
riid,
pvObj);
}
if (!SUCCEEDED(hRet))
{
DbgPrint("IBandSiteStreamCallback::OnLoad(0x%p, 0x%p, 0x%p) returns 0x%x\n", pStm, riid, pvObj, hRet);
}
return hRet;
}
static HRESULT STDMETHODCALLTYPE
ITrayBandSiteImpl_OnSave(IN OUT ITrayBandSite *iface,
IN OUT IUnknown *pUnk,
IN OUT IStream *pStm)
{
/* NOTE: Callback routine called by the shell while saving the task band
stream. We use it to intercept the default behavior when the task
band is saved to the stream */
/* FIXME: Implement */
DbgPrint("IBandSiteStreamCallback::OnSave(0x%p, 0x%p) returns E_NOTIMPL\n", pUnk, pStm);
return E_NOTIMPL;
}
static HRESULT
IsSameObject(IN IUnknown *punk1,
IN IUnknown *punk2)
{
HRESULT hRet;
hRet = IUnknown_QueryInterface(punk1,
&IID_IUnknown,
(PVOID*)&punk1);
if (!SUCCEEDED(hRet))
return hRet;
hRet = IUnknown_QueryInterface(punk2,
&IID_IUnknown,
(PVOID*)&punk2);
IUnknown_Release(punk1);
if (!SUCCEEDED(hRet))
return hRet;
IUnknown_Release(punk2);
/* We're dealing with the same object if the IUnknown pointers are equal */
return (punk1 == punk2) ? S_OK : S_FALSE;
}
static HRESULT STDMETHODCALLTYPE
ITrayBandSiteImpl_IsTaskBand(IN OUT ITrayBandSite *iface,
IN IUnknown *punk)
{
ITrayBandSiteImpl *This = ITrayBandSiteImpl_from_ITrayBandSite(iface);
return IsSameObject((IUnknown *)This->BandSite,
punk);
}
static HRESULT STDMETHODCALLTYPE
ITrayBandSiteImpl_ProcessMessage(IN OUT ITrayBandSite *iface,
IN HWND hWnd,
IN UINT uMsg,
IN WPARAM wParam,
IN LPARAM lParam,
OUT LRESULT *plResult)
{
ITrayBandSiteImpl *This = ITrayBandSiteImpl_from_ITrayBandSite(iface);
HRESULT hRet;
ASSERT(This->hWndRebar != NULL);
/* Custom task band behavior */
switch (uMsg)
{
case WM_NOTIFY:
{
const NMHDR *nmh = (const NMHDR *)lParam;
if (nmh->hwndFrom == This->hWndRebar)
{
switch (nmh->code)
{
case NM_NCHITTEST:
{
LPNMMOUSE nmm = (LPNMMOUSE)lParam;
if (nmm->dwHitInfo == RBHT_CLIENT || nmm->dwItemSpec == (DWORD_PTR)-1)
{
/* Make the rebar control appear transparent so the user
can drag the tray window */
*plResult = HTTRANSPARENT;
}
return S_OK;
}
case RBN_MINMAX:
/* Deny if an Administrator disabled this "feature" */
*plResult = (SHRestricted(REST_NOMOVINGBAND) != 0);
return S_OK;
}
}
//DbgPrint("ITrayBandSite::ProcessMessage: WM_NOTIFY for 0x%p, From: 0x%p, Code: NM_FIRST-%u...\n", hWnd, nmh->hwndFrom, NM_FIRST - nmh->code);
break;
}
};
/* Forward to the shell's IWindowEventHandler interface to get the default
shell behavior! */
if (This->WindowEventHandler != NULL)
{
DbgPrint("Calling IWindowEventHandler::ProcessMessage(0x%p, 0x%x, 0x%p, 0x%p, 0x%p) This->hWndRebar=0x%p\n", hWnd, uMsg, wParam, lParam, plResult, This->hWndRebar);
hRet = IWindowEventHandler_ProcessMessage(This->WindowEventHandler,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -