Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public bool HasInvalidPaths(PDFXEdit.IPXC_Annotation annot)
{
uint invalidCount = 0;
uint GoTo = pxsInst.StrToAtom("GoTo");
uint GoToR = pxsInst.StrToAtom("GoToR");
uint Launch = pxsInst.StrToAtom("Launch");
PDFXEdit.IPXC_ActionsList actions = annot.get_Actions(PDFXEdit.PXC_TriggerType.Trigger_Up);
for (uint k = 0; k < actions.Count; k++)
{
if ((actions[k].Type == GoTo) || (actions[k].Type == GoToR))
{
PDFXEdit.IPXC_Action_Goto actionGoTo = (PDFXEdit.IPXC_Action_Goto)actions[k];
if (actionGoTo.IsValid == false)
{
invalidCount++;
}
else if (actions[k].Type == GoToR)
{
PDFXEdit.IPXC_FileSpec path = actionGoTo.Target;
if (File.Exists(path.DIPath) == false)
invalidCount++;
}
}
else if (actions[k].Type == Launch)
{
PDFXEdit.IPXC_Action_Launch actionLaunch = (PDFXEdit.IPXC_Action_Launch)actions[k];
if (actionLaunch.IsValid == false)
{
invalidCount++;
}
else
{
PDFXEdit.IPXC_FileSpec path = actionLaunch.FileSpec;
if (path == null)
{
if (File.Exists(actionLaunch.FileName) == false)
invalidCount++;
}
else
{
if (File.Exists(path.DIPath) == false)
invalidCount++;
}
}
}
}
return (invalidCount > 0);
}
//Target that will contain the custom event handler implementation for the given object
public CustomEventTarget myEventTarget = null; //PS: Do not forget to dispose of it (we do it in Form1_FormClosed)
private void initilaizeCustomEventListenerToolStripMenuItem_Click(object sender, EventArgs e)
{
//Creating the drop target and filling it's supported formats
myEventTarget = new CustomEventTarget(pdfCtl.Doc.ActiveView.PagesView.Obj, this);
}
public partial class CustomEventTarget:
PDFXEdit.IUIX_ObjImpl,
IDisposable
{
//Here we push custom implementation of the PagesView
public CustomEventTarget(PDFXEdit.IUIX_Obj obj, MainFrm parentForm)
{
Obj_ = obj;
if (Obj_ != null)
Obj_.PushImpl(this);
Parent = parentForm;
}
~CustomEventTarget()
{
Dispose();
}
//Disposing of all of the links we made with objects and parent
public void Dispose()
{
Parent = null;
if (Disposed_)
return;
Disposed_ = true;
if (Obj_ != null)
{
Obj_.PopImpl(this);
System.Runtime.InteropServices.Marshal.ReleaseComObject(Obj_);
Obj_ = null;
}
}
//Main form - a parent that in our case holds the PDFXEdit control
public MainFrm Parent = null;
//Object for which we are implementing the custom event listener
public PDFXEdit.IUIX_Obj Obj_;
//Used for single dispose control
private bool Disposed_ = false;
// IUIX_ObjImpl
public PDFXEdit.IUIX_Obj Obj
{
get { return this.Obj_; }
}
//Getting Y coordinate from event param2
public static short HiWord(uint dword)
{
return (short)(dword >> 16);
}
//Getting X coordinate from event param2
public static short LoWord(uint dword)
{
return (short)dword;
}
//Event listener that listens for all of the needed events
public void OnEvent(PDFXEdit.IUIX_Obj pSender, PDFXEdit.IUIX_Event pEvent)
{
//If the event is not handled then it will be
pEvent.Handled = false;
//
if (pEvent.Code == (int)0x0201) //WM_LBUTTONDOWN
{
PDFXEdit.tagPOINT pt;
pt.x = LoWord(pEvent.Param2);
pt.y = HiWord(pEvent.Param2);
int nHitTestCode = 0;
PDFXEdit.IPXC_Annotation annot = Parent.pdfCtl.Doc.ActiveView.PagesView.GetAnnotFromPt(ref pt, out nHitTestCode);
if (annot != null)
{
//Getting atom from IPXS_Inst
uint linkAnnotType = Parent.pxsInst.StrToAtom("Link");
if (annot.Type == linkAnnotType)
{
//If there are any invalid paths then we mark event as handled and this will not execute link action
pEvent.Handled = true;
if (Parent.HasInvalidPaths(annot) == false)
pEvent.Handled = false; //Else we go through link
}
}
}
else if (pEvent.Code == (int)PDFXEdit.UIX_EventCodes.e_BeforeDestroy)
{
Dispose();
}
else if (pEvent.Code == (int)PDFXEdit.UIX_EventCodes.e_Last)
{
Dispose();
}
}
public void OnPostEvent(PDFXEdit.IUIX_Obj pSender, PDFXEdit.IUIX_Event pEvent)
{
}
public void OnPreEvent(PDFXEdit.IUIX_Obj pSender, PDFXEdit.IUIX_Event pEvent)
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.