Created
April 13, 2016 15:12
-
-
Save Polaringu/f3de7fdebf688028d1dbc265695e364c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
// In case of the signatures, we will need to handle LMB click and double click | |
if ((pEvent.Code == (int)0x0201) //WM_LBUTTONDOWN | |
|| (pEvent.Code == (int)0x0203)) //WM_LBUTTONDBLCLK | |
{ | |
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 widgetAnnotType = Parent.pxsInst.StrToAtom("Widget"); | |
if (annot.Type == widgetAnnotType) | |
{ | |
if (annot.Field != null) | |
{ | |
if (annot.Field.Type == PDFXEdit.PXC_FormFieldType.FFT_Signature) | |
{ | |
Parent.pdfCtl.Doc.CoreDoc.CosDocument.LockDocument(); | |
bool bIsEmpty = true; | |
do | |
{ | |
if (annot.Field.PDFObject == null) | |
break; | |
PDFXEdit.IPXS_PDFVariant var = annot.Field.PDFObject.Dict_Get("V"); | |
if (var == null) | |
break; | |
if (var.Type != PDFXEdit.PXS_PDFVariantType.PVT_Dictionary) | |
break; | |
bIsEmpty = false; | |
} while (false); | |
Parent.pdfCtl.Doc.CoreDoc.CosDocument.UnlockDocument(); | |
if (bIsEmpty == true) | |
{ | |
pEvent.Handled = true; | |
////////////////////////////////////////////////////////////////////// | |
//Paste your code here | |
////////////////////////////////////////////////////////////////////// | |
} | |
} | |
} | |
} | |
} | |
} | |
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) | |
{ | |
} | |
} | |
//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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment