Page 1 of 1

How to determine field under the mouse-position

Posted: Thu Nov 12, 2015 4:19 pm
by prosozial_schmitt
Hello,

we need to implement to "drag" a text from outside the viewer into a form field of a pdf inside the viewer. Because of the missing "drag and drop"-feature we have to find an alternative way to do that.

Is it possible to get the name of the form field under the current mouse-position?
If this would be possible, we could get the fieldname at the current mouseposition on mousebutton up and set it programmatically to the desired value.

It would also be good to set the focus in an form-field to make it easier to "navigate the user" to a specific field.

Do you see possibilities to do this?


Greetings
Hans-Peter

Re: How to determine field under the mouse-position

Posted: Fri Nov 13, 2015 10:34 am
by Tracker Supp-Stefan
Hello Hans-Peter,

Passed this question to the appropriate developer, but he is in our Canadian office, so the reply will be posted here a bit later.

Regards,
Stefan

Re: How to determine field under the mouse-position

Posted: Mon Nov 16, 2015 9:04 pm
by Vasyl-Tracker Dev Team
Hi, Hans-Peter.

1. Firstly you need to handle the "Notifications.Mouse" notification and the get from it:

"Notifications.Mouse.x" / "Notifications.Mouse.y"
- mouse screen cursor coordinates

"Notifications.Mouse.Page"
- index of page that is under mouse cursor

2. Then you may use the "ViewPointsToPagePoints" method of page object to translate screen-point to point on the page:

Code: Select all

object[] args = new object[4];
args[0] = mouseX;
args[1] = mouseY;

// translating coords to page coord-space:
object dataOut;
axCoPDFXCview1.DoDocumentVerb(0, "Pages[" + pageIdx + "]", "ViewPointsToPagePoints", dataIn, out dataOut, (int)PXCVA_Flags.PXCVA_Sync);

object[] res = (object[])dataOut;
double pageX = (double)res[0];
double pageY = (double)res[1];
3. Then use:

Code: Select all

// get annots cont on the page:
object dataOut;
axCoPDFXCview1.DoDocumentVerb(0, "Pages[" + pageIdx + "]", "GetAnnotsCount", stub, out dataOut, (int)PXCVA_Flags.PXCVA_Sync);

int annotsCnt = (int)dataOut;
int fieldIndex = -1;
for (int i = (annotsCnt - 1); i >= 0; i--)
{
    object annotIdx = (object)i;
    axCoPDFXCview1.DoDocumentVerb(0, "Pages[" + pageIdx + "]", "GetAnnotRect", annotIdx, out dataOut, (int)PXCVA_Flags.PXCVA_Sync);
    object[] rect = (object[])dataOut; // 4 numbers
    double left = (double)rect[0];
    double top = (double)rect[1];
    double right = (double)rect[2];
    double bottom = (double)rect[3];
    if (PtInRect(pageX, pageY, left, top, right, bottom))
    {
          axCoPDFXCview1.DoDocumentVerb(0, "Pages[" + pageIdx + "]", "GetAnnotType", annotIdx, out dataOut, (int)PXCVA_Flags.PXCVA_Sync);     
          int annotType = (int)dataOut;
          if (annotType == 4) // widget/field
          {
                 fieldIndex = i;
                 break; 
          }
    }
}

// now you may select annot(widget)
if (fieldIndex >= 0)
{
       axCoPDFXCview1.DoDocumentVerb(0, "Pages[" + pageIdx + "]", "SelectAnnot", (object)fieldIndex, out dataOut, (int)PXCVA_Flags.PXCVA_Sync);
       // and get name of selected field
       axCoPDFXCview1.DoDocumentVerb(0, "Pages[" + pageIdx + "]", "GetSelectedField", (object)fieldIndex, out dataOut, (int)PXCVA_Flags.PXCVA_Sync); 
       string selFieldName = (string)dataOut;
} 
// - sorry but no way to get field name without selecting it before...
HTH.

Re: How to determine field under the mouse-position

Posted: Wed Nov 18, 2015 9:18 am
by prosozial_schmitt
Hello Vasyl,

thank you for your sample. I'll try to implement it.
:)

Greetings
Hans-Peter

Re: How to determine field under the mouse-position

Posted: Wed Nov 18, 2015 11:43 am
by Tracker Supp-Stefan
:)