HWND curTargetHWND; /* window the mouse is hovering over */
HWND curDragTargetHWND; /* might be a ancestor of curTargetHWND */
IDropTarget* curDragTarget;
+ POINTL curMousePos; /* current position of the mouse in screen coordinates */
+ DWORD dwKeyState; /* current state of the shift and ctrl keys and the mouse buttons */
} TrackerWindowInfo;
typedef struct tagOleMenuDescriptor /* OleMenuDescriptor */
WPARAM wParam,
LPARAM lParam);
static void OLEDD_TrackMouseMove(
- TrackerWindowInfo* trackerInfo,
- POINT mousePos,
- DWORD keyState);
+ TrackerWindowInfo* trackerInfo);
static void OLEDD_TrackStateChange(
- TrackerWindowInfo* trackerInfo,
- POINT mousePos,
- DWORD keyState);
+ TrackerWindowInfo* trackerInfo);
static DWORD OLEDD_GetButtonState(void);
*/
while (!trackerInfo.trackingDone && GetMessageA(&msg, 0, 0, 0) )
{
+ trackerInfo.curMousePos.x = msg.pt.x;
+ trackerInfo.curMousePos.y = msg.pt.y;
+ trackerInfo.dwKeyState = OLEDD_GetButtonState();
+
if ( (msg.message >= WM_KEYFIRST) &&
(msg.message <= WM_KEYLAST) )
{
/*
* Notify the drop source.
*/
- OLEDD_TrackStateChange(&trackerInfo,
- msg.pt,
- OLEDD_GetButtonState());
+ OLEDD_TrackStateChange(&trackerInfo);
}
else
{
* to receive the user input and act upon it. This procedure is in charge
* of this behavior.
*/
+
+#define DRAG_TIMER_ID 1
+
static LRESULT WINAPI OLEDD_DragTrackerWindowProc(
HWND hwnd,
UINT uMsg,
LPCREATESTRUCTA createStruct = (LPCREATESTRUCTA)lParam;
SetWindowLongA(hwnd, 0, (LONG)createStruct->lpCreateParams);
-
+ SetTimer(hwnd, DRAG_TIMER_ID, 50, NULL);
break;
}
+ case WM_TIMER:
case WM_MOUSEMOVE:
{
- TrackerWindowInfo* trackerInfo = (TrackerWindowInfo*)GetWindowLongA(hwnd, 0);
- POINT mousePos;
-
- /*
- * Get the current mouse position in screen coordinates.
- */
- mousePos.x = LOWORD(lParam);
- mousePos.y = HIWORD(lParam);
- ClientToScreen(hwnd, &mousePos);
-
- /*
- * Track the movement of the mouse.
- */
- OLEDD_TrackMouseMove(trackerInfo, mousePos, wParam);
-
+ OLEDD_TrackMouseMove((TrackerWindowInfo*)GetWindowLongA(hwnd, 0));
break;
}
case WM_LBUTTONUP:
case WM_MBUTTONDOWN:
case WM_RBUTTONDOWN:
{
- TrackerWindowInfo* trackerInfo = (TrackerWindowInfo*)GetWindowLongA(hwnd, 0);
- POINT mousePos;
-
- /*
- * Get the current mouse position in screen coordinates.
- */
- mousePos.x = LOWORD(lParam);
- mousePos.y = HIWORD(lParam);
- ClientToScreen(hwnd, &mousePos);
-
- /*
- * Notify everyone that the button state changed
- * TODO: Check if the "escape" key was pressed.
- */
- OLEDD_TrackStateChange(trackerInfo, mousePos, wParam);
-
+ OLEDD_TrackStateChange((TrackerWindowInfo*)GetWindowLongA(hwnd, 0));
+ break;
+ }
+ case WM_DESTROY:
+ {
+ KillTimer(hwnd, DRAG_TIMER_ID);
break;
}
}
* trackerInfo - Pointer to the structure identifying the
* drag & drop operation that is currently
* active.
- * mousePos - Current position of the mouse in screen
- * coordinates.
- * keyState - Contains the state of the shift keys and the
- * mouse buttons (MK_LBUTTON and the like)
*/
-static void OLEDD_TrackMouseMove(
- TrackerWindowInfo* trackerInfo,
- POINT mousePos,
- DWORD keyState)
+static void OLEDD_TrackMouseMove(TrackerWindowInfo* trackerInfo)
{
HWND hwndNewTarget = 0;
HRESULT hr = S_OK;
+ POINT pt;
/*
* Get the handle of the window under the mouse
*/
- hwndNewTarget = WindowFromPoint(mousePos);
+ pt.x = trackerInfo->curMousePos.x;
+ pt.y = trackerInfo->curMousePos.y;
+ hwndNewTarget = WindowFromPoint(pt);
/*
* Every time, we re-initialize the effects passed to the
if ( (trackerInfo->curDragTarget != 0) &&
(trackerInfo->curTargetHWND == hwndNewTarget) )
{
- POINTL mousePosParam;
-
- /*
- * The documentation tells me that the coordinate should be in the target
- * window's coordinate space. However, the tests I made tell me the
- * coordinates should be in screen coordinates.
- */
- mousePosParam.x = mousePos.x;
- mousePosParam.y = mousePos.y;
-
IDropTarget_DragOver(trackerInfo->curDragTarget,
- keyState,
- mousePosParam,
+ trackerInfo->dwKeyState,
+ trackerInfo->curMousePos,
trackerInfo->pdwEffect);
}
else
*/
if (trackerInfo->curDragTarget!=0)
{
- POINTL mousePosParam;
-
- /*
- * The documentation tells me that the coordinate should be in the target
- * window's coordinate space. However, the tests I made tell me the
- * coordinates should be in screen coordinates.
- */
- mousePosParam.x = mousePos.x;
- mousePosParam.y = mousePos.y;
-
IDropTarget_DragEnter(trackerInfo->curDragTarget,
trackerInfo->dataObject,
- keyState,
- mousePosParam,
+ trackerInfo->dwKeyState,
+ trackerInfo->curMousePos,
trackerInfo->pdwEffect);
}
}
* trackerInfo - Pointer to the structure identifying the
* drag & drop operation that is currently
* active.
- * mousePos - Current position of the mouse in screen
- * coordinates.
- * keyState - Contains the state of the shift keys and the
- * mouse buttons (MK_LBUTTON and the like)
*/
-static void OLEDD_TrackStateChange(
- TrackerWindowInfo* trackerInfo,
- POINT mousePos,
- DWORD keyState)
+static void OLEDD_TrackStateChange(TrackerWindowInfo* trackerInfo)
{
/*
* Ask the drop source what to do with the operation.
trackerInfo->returnValue = IDropSource_QueryContinueDrag(
trackerInfo->dropSource,
trackerInfo->escPressed,
- keyState);
+ trackerInfo->dwKeyState);
/*
* All the return valued will stop the operation except the S_OK
*/
case DRAGDROP_S_DROP:
{
- POINTL mousePosParam;
-
- /*
- * The documentation tells me that the coordinate should be
- * in the target window's coordinate space. However, the tests
- * I made tell me the coordinates should be in screen coordinates.
- */
- mousePosParam.x = mousePos.x;
- mousePosParam.y = mousePos.y;
-
IDropTarget_Drop(trackerInfo->curDragTarget,
trackerInfo->dataObject,
- keyState,
- mousePosParam,
+ trackerInfo->dwKeyState,
+ trackerInfo->curMousePos,
trackerInfo->pdwEffect);
break;
}
*/
if (This->smallBlockChain!=0)
{
- SmallBlockChainStream_ReadAt(This->smallBlockChain,
+ res = SmallBlockChainStream_ReadAt(This->smallBlockChain,
This->currentPosition,
bytesToReadFromBuffer,
pv,
}
else if (This->bigBlockChain!=0)
{
- BlockChainStream_ReadAt(This->bigBlockChain,
+ res = BlockChainStream_ReadAt(This->bigBlockChain,
This->currentPosition,
bytesToReadFromBuffer,
pv,
goto end;
}
- /*
- * We should always be able to read the proper amount of data from the
- * chain.
- */
- assert(bytesToReadFromBuffer == *pcbRead);
-
- /*
- * Advance the pointer for the number of positions read.
- */
- This->currentPosition.u.LowPart += *pcbRead;
-
- if(*pcbRead != cb)
+ if (SUCCEEDED(res))
{
- WARN("read %ld instead of the required %ld bytes !\n", *pcbRead, cb);
- /*
- * this used to return S_FALSE, however MSDN docu says that an app should
- * be prepared to handle error in case of stream end reached, as *some*
- * implementations *might* return an error (IOW: most do *not*).
- * As some program fails on returning S_FALSE, I better use S_OK here.
- */
- res = S_OK;
+ /*
+ * We should always be able to read the proper amount of data from the
+ * chain.
+ */
+ assert(bytesToReadFromBuffer == *pcbRead);
+
+ /*
+ * Advance the pointer for the number of positions read.
+ */
+ This->currentPosition.u.LowPart += *pcbRead;
}
- else
- res = S_OK;
end:
TRACE("<-- %08lx\n", res);
ULARGE_INTEGER size, offset;
ULONG cbRead, cbWritten, cbTotalRead, cbTotalWritten;
ULONG propertyIndex;
- BOOL successRead, successWrite;
+ BOOL successWrite;
+ HRESULT successRead;
StgProperty chainProperty;
BYTE *buffer;
BlockChainStream *bbTempChain = NULL;
offset.u.LowPart += This->smallBlockSize;
- } while (successRead && successWrite);
+ } while (SUCCEEDED(successRead) && successWrite);
HeapFree(GetProcessHeap(),0,buffer);
assert(cbTotalRead == cbTotalWritten);
blockNoInSequence--;
}
+ if ((blockNoInSequence > 0) && (blockIndex == BLOCK_END_OF_CHAIN))
+ return FALSE; /* We failed to find the starting block */
+
This->lastBlockNoInSequenceIndex = blockIndex;
/*
* bytesRead may be NULL.
* Failure will be returned if the specified number of bytes has not been read.
*/
-BOOL SmallBlockChainStream_ReadAt(
+HRESULT SmallBlockChainStream_ReadAt(
SmallBlockChainStream* This,
ULARGE_INTEGER offset,
ULONG size,
void* buffer,
ULONG* bytesRead)
{
+ HRESULT rc = S_OK;
ULARGE_INTEGER offsetInBigBlockFile;
ULONG blockNoInSequence =
offset.u.LowPart / This->parentStorage->smallBlockSize;
while ( (blockNoInSequence > 0) && (blockIndex != BLOCK_END_OF_CHAIN))
{
- if(FAILED(SmallBlockChainStream_GetNextBlockInChain(This, blockIndex,
- &blockIndex)))
- return FALSE;
+ rc = SmallBlockChainStream_GetNextBlockInChain(This, blockIndex, &blockIndex);
+ if(FAILED(rc))
+ return rc;
blockNoInSequence--;
}
/*
* Read those bytes in the buffer from the small block file.
+ * The small block has already been identified so it shouldn't fail
+ * unless the file is corrupt.
*/
- BlockChainStream_ReadAt(This->parentStorage->smallBlockRootChain,
+ if (!BlockChainStream_ReadAt(This->parentStorage->smallBlockRootChain,
offsetInBigBlockFile,
bytesToReadInBuffer,
bufferWalker,
- &bytesReadFromBigBlockFile);
+ &bytesReadFromBigBlockFile))
+ return STG_E_DOCFILECORRUPT;
assert(bytesReadFromBigBlockFile == bytesToReadInBuffer);
/*
* Step to the next big block.
*/
- if(FAILED(SmallBlockChainStream_GetNextBlockInChain(This, blockIndex, &blockIndex)))
- return FALSE;
+ rc = SmallBlockChainStream_GetNextBlockInChain(This, blockIndex, &blockIndex);
+ if(FAILED(rc))
+ return rc;
+
bufferWalker += bytesToReadInBuffer;
size -= bytesToReadInBuffer;
*bytesRead += bytesToReadInBuffer;
offsetInBlock = 0; /* There is no offset on the next block */
}
- return (size == 0);
+ return rc;
}
/******************************************************************************