How to determine field under the mouse-position  SOLVED

PDF-XChange Viewer SDK for Developer's
(ActiveX and Simple DLL Versions)

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Sean - Tracker, Chris - Tracker Supp, Tracker Supp-Stefan, Ivan - Tracker Software

Post Reply
prosozial_schmitt
User
Posts: 52
Joined: Tue Dec 28, 2004 9:49 am

How to determine field under the mouse-position

Post by prosozial_schmitt » Thu Nov 12, 2015 4:19 pm

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

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 13524
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: How to determine field under the mouse-position

Post by Tracker Supp-Stefan » Fri Nov 13, 2015 10:34 am

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

User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 1928
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: How to determine field under the mouse-position

Post by Vasyl-Tracker Dev Team » Mon Nov 16, 2015 9:04 pm

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.
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.

prosozial_schmitt
User
Posts: 52
Joined: Tue Dec 28, 2004 9:49 am

Re: How to determine field under the mouse-position

Post by prosozial_schmitt » Wed Nov 18, 2015 9:18 am

Hello Vasyl,

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

Greetings
Hans-Peter

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 13524
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: How to determine field under the mouse-position

Post by Tracker Supp-Stefan » Wed Nov 18, 2015 11:43 am

:)

Post Reply