pdfSetMouseMoveWinCbk
Set a callback function for mouse movement events with window coordinates.
void pdfSetMouseMoveWinCbk(PDFViewerHandle viewer,
void (*cbk)(void *data, int button, int shift,
int winX, int winY),
void *data)
This function sets a callback which will be called when the user moves
the mouse.
The function will be called with six arguments:
data
: the value of thedata
argument that was passed topdfSetMouseMoveCbk
button
: the mouse button number - one ofpdfLeftButton
,pdfMiddleButton
, orpdfRightButton
, or 0 if no mouse button is pressedshift
: the shift/control/alt bit mask, which contains zero or more bit flags frompdfShiftKey
,pdfCtrlKey
, andpdfAltKey
winX, winY
: the current position of the mouse cursor, in PDF coordinates
pdfConvertWindowToPDFCoords2
.
This callback is similar to pdfSetMouseMoveCbk
, except that (a) it
is called with window coordinates instead of PDF coordinates, and (b)
it will be called even if the mouse is moved outside of a PDF page.
IMPORTANT: In order to
receive pdfSetMouseMoveWinCbk
and pdfSetMouseUpWinCbk
callbacks when the mouse is outside the XpdfViewer window (not just
outside the PDF pages), you must call SetCapture
in the
pdfSetMouseDownWinCbk
callback. See the example below.
C:
void mouseDownWinCbk(void *data, int button, int shift,
int winX, int winY) {
Context *myContext = (Context *)data;
int pg;
double x, y;
pdfConvertWindowToPDFCoords2(viewer, winX, winY, &pg, &x, &y);
/* ... use pg, x, y ... */
/* capture the mouse so we receive Move and Up events outside the window */
SetCapture(pdfGetWindowHandle(viewer));
}
void mouseUpWinCbk(void *data, int button, int shift,
int winX, int winY) {
Context *myContext = (Context *)data;
int pg;
double x, y;
/* release the capture that was initiated in the Down callback */
ReleaseCapture();
pdfConvertWindowToPDFCoords2(viewer, winX, winY, &pg, &x, &y);
/* ... use pg, x, y ... */
}
void mouseMoveWinCbk(void *data, int button, int shift,
int winX, int winY) {
Context *myContext = (Context *)data;
int pg;
double x, y;
pdfConvertWindowToPDFCoords2(viewer, winX, winY, &pg, &x, &y);
/* ... use pg, x, y ... */
}
....
pdfSetMouseDownWinCbk(viewer, &mouseDownWinCbk, &myContext);
pdfSetMouseUpWinCbk(viewer, &mouseDownWinCbk, &myContext);
pdfSetMouseMoveWinCbk(viewer, &mouseDownWinCbk, &myContext);