Detecting whether an annotation is selected or deselected

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

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

Post Reply
relapse
User
Posts: 167
Joined: Wed Jan 18, 2012 11:10 am

Detecting whether an annotation is selected or deselected

Post by relapse »

Hi! How can I detect it? I already can test whether an annotation is selected:

Code: Select all

            pdfViewer.SetProperty("Notifications.Selection.Filter", -1, 0);
            if (e.name.Equals("Notifications.Selection"))
            { AnnotIsSelected = true; }
But how could I get a message from the viewer when the selected annotation is deselected?



Thanks for your replies!
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2353
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: Detecting whether an annotation is selected or deselecte

Post by Vasyl-Tracker Dev Team »

Hi, relapse

The correct code is:

Code: Select all

pdfViewer.SetProperty("Notifications.Selection.Filter", -1, 0);
...
pdfViewer.SetSocumentProperty(justOpenedDocID, "GetSelMarkupsOnly", "true"); // to modify behavior of 'GetSelectedAnnot' feature to ignore all form fields (if needed)
...
...
eventhandler OnEvent(type, name, ...)
{
    if ((type == PXCVA_OnNamedNotify) && (e.name.Equals("Notifications.Selection")))
    { 
         AnnotIsSelected = false; 
         object docID = 0;   
         pdfViewer.GetProperty("Notifications.Selection.Document", out docID, 0);
         if ((int)docID != 0)
         {
               object selectedAnnotPageAndIndexOnPage;
               pdfViewer.DoDocumentVerb(docID, null, "GetSelectedAnnot", null, out selectedAnnotPageAndIndexOnPage, PXCVA_OutArgs);
               PDFXCviewAxLib.IPDFXCargs outArgs = (PDFXCviewAxLib.IPDFXCargs)selectedAnnotPageAndIndexOnPage;
               if ((outArgs.Count > 0) && (outArgs[0] >= 0))
                    AnnotIsSelected = true; 
         }
    }
}
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.
relapse
User
Posts: 167
Joined: Wed Jan 18, 2012 11:10 am

Re: Detecting whether an annotation is selected or deselecte

Post by relapse »

Hi! I've tried your code sample and I detected that after the command:

Code: Select all

PDFXCviewAxLib.IPDFXCargs outArgs = (PDFXCviewAxLib.IPDFXCargs)selectedAnnotPageAndIndexOnPage;
no code is executed. So I've modified it a little bit this way:

Code: Select all

            if ((e.type == 4) && (e.name.Equals("Notifications.Selection")))
            {
                object docID;
                pdfViewer.GetProperty("Notifications.Selection.Document", out docID, 0);
                if ((int)docID != 0)
                {
                    object selectedAnnotPageAndIndexOnPage;
                    pdfViewer.DoDocumentVerb((int)docID, null, "GetSelectedAnnot", null, out selectedAnnotPageAndIndexOnPage, 10);
                    var intArray = (int[])selectedAnnotPageAndIndexOnPage;
                    if (intArray.Length > 0 && intArray[0] > -1)
                    {
                        AnnotIsSelected = true;
                    }
                    else
                    {
                        AnnotIsSelected = false;
                    }
                }
            }
It functions! Thanks a lot!

P.S. If an annotation is selected the selectedAnnotPageAndIndexOnPage object is [0]=0, [1]=0, [2]=4106. If deselected - [0]=-1, [1]=-1, [2]=0. What do these values mean?
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17938
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Detecting whether an annotation is selected or deselecte

Post by Tracker Supp-Stefan »

Hi Relapse,

Glad to hear that it's working.

GetSelectedAnnot returns two values:
1 LONG The zero-based index of page with the selected annotation. But, if no selected
annotation then control will return -1 as page index and result of method calling will
be S_FALSE.
2 LONG The zero-based index of annotation on the page.

And when no annotation is selected the value of both is -1, I presume the third value is the DocID but will need to double check that.

Best,
Stefan
Post Reply