+ minor refactorings

This commit is contained in:
Rainer Kottenhoff 2017-11-29 01:10:56 +01:00
parent c8501af6c7
commit 5cd238f918
3 changed files with 39 additions and 27 deletions

View File

@ -3588,8 +3588,6 @@ INT UTF8_mbslen(LPCSTR source,INT byte_length)
static HANDLE g_hHeap = NULL;
#define NP3DD_HEAP (g_hHeap == NULL ? (g_hHeap = GetProcessHeap()) : g_hHeap)
typedef struct tIDROPTARGET {
IDropTarget idt;
LONG lRefCount;
@ -3601,7 +3599,7 @@ typedef struct tIDROPTARGET {
IDataObject *pDataObject;
UINT nMsg;
void *pUserData;
NP3DDCALLBACK pDropProc;
DNDCALLBACK pDropProc;
}
IDROPTARGET, *PIDROPTARGET;
@ -3623,9 +3621,9 @@ IDRPTRG_VTBL, *PIDRPTRG_VTBL;
//=============================================================================
//
// NP3DragnDropInit()
// DragAndDropInit()
//
void DragnDropInit(HANDLE hHeap)
void DragAndDropInit(HANDLE hHeap)
{
if (g_hHeap == NULL && hHeap == NULL)
g_hHeap = GetProcessHeap();
@ -3637,6 +3635,19 @@ void DragnDropInit(HANDLE hHeap)
}
//=============================================================================
//
// GetDnDHeap()
//
static HANDLE GetDnDHeap()
{
if (g_hHeap == NULL) {
g_hHeap = GetProcessHeap();
}
return g_hHeap;
}
//=============================================================================
//
// IDRPTRG_AddRef()
@ -3703,7 +3714,7 @@ static ULONG STDMETHODCALLTYPE IDRPTRG_Release(PIDROPTARGET pThis)
if ((nCount = InterlockedDecrement(&pThis->lRefCount)) == 0)
{
HeapFree(NP3DD_HEAP, 0, pThis);
HeapFree(GetDnDHeap(), 0, pThis);
return 0;
}
@ -3816,9 +3827,9 @@ static HRESULT STDMETHODCALLTYPE IDRPTRG_Drop(PIDROPTARGET pThis, IDataObject *p
{
pDataObject->lpVtbl->GetData(pDataObject, &fmtetc, &medium);
*pdwEffect = DROPEFFECT_NONE;
if (pThis->pDropProc != NULL)
*pdwEffect = (*pThis->pDropProc)(pThis->pFormat[lFmt], medium.hGlobal, pThis->hWnd, pThis->dwKeyState,
pt, pThis->pUserData);
if (pThis->pDropProc != NULL) {
*pdwEffect = (*pThis->pDropProc)(pThis->pFormat[lFmt], medium.hGlobal, pThis->hWnd, pThis->dwKeyState, pt, pThis->pUserData);
}
else if (pThis->nMsg != WM_NULL)
{
DropData.cf = pThis->pFormat[lFmt];
@ -3826,8 +3837,7 @@ static HRESULT STDMETHODCALLTYPE IDRPTRG_Drop(PIDROPTARGET pThis, IDataObject *p
DropData.hData = medium.hGlobal;
DropData.pt = pt;
*pdwEffect = (DWORD)SendMessage(pThis->hWnd, pThis->nMsg, (WPARAM)&DropData,
(LPARAM)pThis->pUserData);
*pdwEffect = (DWORD)SendMessage(pThis->hWnd, pThis->nMsg, (WPARAM)&DropData, (LPARAM)pThis->pUserData);
}
if (*pdwEffect != DROPEFFECT_NONE)
ReleaseStgMedium(&medium);
@ -3842,7 +3852,7 @@ static HRESULT STDMETHODCALLTYPE IDRPTRG_Drop(PIDROPTARGET pThis, IDataObject *p
//=============================================================================
//
// Np3CreateDropTarget()
// CreateDropTarget()
//
IDropTarget* CreateDropTarget(CLIPFORMAT *pFormat, ULONG lFmt, HWND hWnd, UINT nMsg,
DWORD(*pDropProc)(CLIPFORMAT cf, HGLOBAL hData, HWND hWnd, DWORD dwKeyState, POINTL pt, void *pUserData),
@ -3858,8 +3868,9 @@ IDropTarget* CreateDropTarget(CLIPFORMAT *pFormat, ULONG lFmt, HWND hWnd, UINT n
IDRPTRG_DragLeave,
IDRPTRG_Drop };
if ((pRet = HeapAlloc(NP3DD_HEAP, 0, sizeof(IDROPTARGET) + lFmt * sizeof(CLIPFORMAT))) == NULL)
if ((pRet = HeapAlloc(GetDnDHeap(), 0, sizeof(IDROPTARGET) + lFmt * sizeof(CLIPFORMAT))) == NULL)
return NULL;
pRet->pFormat = (CLIPFORMAT *)(((char *)pRet) + sizeof(IDROPTARGET));
pRet->idt.lpVtbl = (IDropTargetVtbl*)&idt_vtbl;
@ -3872,9 +3883,9 @@ IDropTarget* CreateDropTarget(CLIPFORMAT *pFormat, ULONG lFmt, HWND hWnd, UINT n
pRet->pDropProc = pDropProc;
pRet->pUserData = pUserData;
for (lFmt = 0; lFmt < pRet->lNumFormats; lFmt++)
for (lFmt = 0; lFmt < pRet->lNumFormats; lFmt++) {
pRet->pFormat[lFmt] = pFormat[lFmt];
}
return (IDropTarget *)pRet;
}
@ -3882,9 +3893,9 @@ IDropTarget* CreateDropTarget(CLIPFORMAT *pFormat, ULONG lFmt, HWND hWnd, UINT n
//=============================================================================
//
// Np3RegisterDragnDrop()
// RegisterDragAndDrop()
//
PDROPTARGET RegisterDragnDrop(HWND hWnd, CLIPFORMAT *pFormat, ULONG lFmt, UINT nMsg, NP3DDCALLBACK pDropProc, void *pUserData)
PDROPTARGET RegisterDragAndDrop(HWND hWnd, CLIPFORMAT *pFormat, ULONG lFmt, UINT nMsg, DNDCALLBACK pDropProc, void *pUserData)
{
IDropTarget *pTarget;
@ -3893,7 +3904,7 @@ PDROPTARGET RegisterDragnDrop(HWND hWnd, CLIPFORMAT *pFormat, ULONG lFmt, UINT n
if (RegisterDragDrop(hWnd, pTarget) != S_OK)
{
HeapFree(NP3DD_HEAP, 0, pTarget);
HeapFree(GetDnDHeap(), 0, pTarget);
return NULL;
}
@ -3903,9 +3914,9 @@ PDROPTARGET RegisterDragnDrop(HWND hWnd, CLIPFORMAT *pFormat, ULONG lFmt, UINT n
//=============================================================================
//
// Np3RevokeDragnDrop()
// RevokeDragAndDrop()
//
PDROPTARGET RevokeDragnDrop(PDROPTARGET pTarget)
PDROPTARGET RevokeDragAndDrop(PDROPTARGET pTarget)
{
if (pTarget == NULL)
return NULL;

View File

@ -448,11 +448,11 @@ typedef struct tDROPDATA
DROPDATA, *PDROPDATA;
typedef struct tDROPTARGET *PDROPTARGET;
typedef DWORD(*NP3DDCALLBACK)(CLIPFORMAT cf, HGLOBAL hData, HWND hWnd, DWORD dwKeyState, POINTL pt, void *pUserData);
typedef DWORD(*DNDCALLBACK)(CLIPFORMAT cf, HGLOBAL hData, HWND hWnd, DWORD dwKeyState, POINTL pt, void *pUserData);
void DragnDropInit(HANDLE hHeap);
PDROPTARGET RegisterDragnDrop(HWND hWnd, CLIPFORMAT *pFormat, ULONG lFmt, UINT nMsg, NP3DDCALLBACK, void *pUserData);
PDROPTARGET RevokeDragnDrop(PDROPTARGET pTarget);
void DragAndDropInit(HANDLE hHeap);
PDROPTARGET RegisterDragAndDrop(HWND hWnd, CLIPFORMAT *pFormat, ULONG lFmt, UINT nMsg, DNDCALLBACK, void *pUserData);
PDROPTARGET RevokeDragAndDrop(PDROPTARGET pTarget);
#endif //_NP3_HELPERS_H_

View File

@ -652,7 +652,7 @@ int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,LPSTR lpCmdLine,int n
return FALSE;
// init DragnDrop handler
DragnDropInit(NULL);
DragAndDropInit(NULL);
if (IsVista()) {
SciCall_UnBufferedDraw(); // Current platforms perform window buffering so it is almost always better for this option to be turned off.
@ -1415,7 +1415,7 @@ LRESULT MsgCreate(HWND hwnd,WPARAM wParam,LPARAM lParam)
// Drag & Drop
DragAcceptFiles(hwnd,TRUE);
pDropTarget = RegisterDragnDrop(hwnd, &cfDrpF, 1, WM_NULL, DropFilesProc, (void*)hwndEdit);
pDropTarget = RegisterDragAndDrop(hwnd, &cfDrpF, 1, WM_NULL, DropFilesProc, (void*)hwndEdit);
// File MRU
pFileMRU = MRU_Create(L"Recent Files",MRU_NOCASE,32);
@ -1638,7 +1638,7 @@ void MsgEndSession(HWND hwnd, UINT umsg)
wininfo = GetMyWindowPlacement(hwnd, NULL);
DragAcceptFiles(hwnd, FALSE);
RevokeDragnDrop(pDropTarget);
RevokeDragAndDrop(pDropTarget);
// Terminate clipboard watching
if (flagPasteBoard) {
@ -1863,6 +1863,7 @@ void MsgDropFiles(HWND hwnd, WPARAM wParam, LPARAM lParam)
else if (PathFileExists(szBuf))
FileLoad(FALSE, FALSE, FALSE, FALSE, szBuf);
else
// Windows Bug: wParam (HDROP) pointer is corrupted if dropped from 32-bit App
MsgBox(MBWARN, IDS_DROP_NO_FILE);
if (DragQueryFile(hDrop, (UINT)(-1), NULL, 0) > 1)