Skip to content

Instantly share code, notes, and snippets.

@Polaringu Polaringu/PdfEditorCommandHandler.cs Secret
Last active Mar 17, 2016

Embed
What would you like to do?
Custom Commands
private void showToolbarsToolStripMenuItem_Click(object sender, EventArgs e)
{
pdfCtl.VisibleCmdPanes = (uint)PDFXEdit.PXV_VisibleCmdPanes.PXV_VisibleCmdPanes_All;
}
class PdfEditorCommandHandler : PDFXEdit.IUIX_CmdHandler
{
public PDFXEdit.IPXV_Inst m_Inst = null;
public PdfEditorCommandHandler(PDFXEdit.IPXV_Inst Inst)
{
m_Inst = Inst;
}
public void OnCreateNewCtl(PDFXEdit.IUIX_Cmd pCmd, PDFXEdit.IUIX_CmdBar pParent, out PDFXEdit.IUIX_Obj pCtl)
{
pCtl = null;
}
public void OnGetCtlSizes(PDFXEdit.IUIX_CmdItem pItem, ref PDFXEdit.tagSIZE nSize, ref PDFXEdit.tagSIZE nMinSize, ref PDFXEdit.tagSIZE nMaxSize)
{
//throw new System.NotImplementedException();
}
public void OnGetItemState(PDFXEdit.IUIX_Cmd pCmd, PDFXEdit.IUIX_CmdItem pItem, PDFXEdit.IUIX_Obj pOwner, out int nState)
{
nState = (int)PDFXEdit.UIX_CmdItemState.UIX_CmdItemState_Unknown;
if (pCmd == null || pItem == null)
{
return;
}
int nOpenID = m_Inst.Str2ID("cmd.open");
if (pCmd.ID == nOpenID) // integer result of str2id method
nState = (int)PDFXEdit.UIX_CmdItemState.UIX_CmdItemState_Normal;
}
public void OnGetItemSubMenu(PDFXEdit.IUIX_CmdItem pItem, out PDFXEdit.IUIX_CmdMenu pSubMenu)
{
pSubMenu = null;
}
public void OnNotify(int nCode, PDFXEdit.IUIX_Cmd pCmd, PDFXEdit.IUIX_CmdItem pItem, PDFXEdit.IUIX_Obj pOwner, uint nNotifyData)
{
if (pCmd == null)
return;
long nOpenID = m_Inst.Str2ID("cmd.open");
if (pCmd.ID == nOpenID)
{
if (nCode == (int)PDFXEdit.UIX_CmdNotifyCodes.UIX_CmdNotify_Exec)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "PDF Files (*.pdf)|*.pdf|All files (*.*)|*.*";
ofd.FilterIndex = 1;
ofd.RestoreDirectory = true;
ofd.CheckFileExists = true;
if(ofd.ShowDialog() == DialogResult.OK)
{
PDFXEdit.ICab openParams = m_Inst.CreateOpenDocParams();
PDFXEdit.ICabNode openParamsRoot = openParams.Root;
int secPerms = (int)PDFXEdit.PXC_PermsFlags.PermF_All & ~((int)PDFXEdit.PXC_SecurityPermissions.Permit_Copying_And_TextGraphicsExtractions | (int)PDFXEdit.PXC_SecurityPermissions.Permit_Printing | (int)PDFXEdit.PXC_SecurityPermissions.Permit_HighQualityPrinting);
openParamsRoot.SetInt("SecPermMask", secPerms);
m_Inst.ActiveMainFrm.OpenDocFromPath(ofd.FileName, openParams);
}
}
}
}
public void OnDrawItemIcon(PDFXEdit.IUIX_RenderContext pRC, PDFXEdit.IUIX_CmdItem pItem, ref PDFXEdit.tagRECT stIconRect, ref PDFXEdit.tagRECT stClip)
{
//throw new System.NotImplementedException();
}
}
PdfEditorCommandHandler cmdHandler = null;
private void customizeSaveCommandToolStripMenuItem_Click(object sender, EventArgs e)
{
cmdHandler = new PdfEditorCommandHandler(pdfCtl.Inst);
PDFXEdit.IUIX_Inst iuiInst = (PDFXEdit.IUIX_Inst)pdfCtl.Inst.GetExtension("UIX");
PDFXEdit.IUIX_Cmd cmd = iuiInst.CmdManager.Cmds.Find("cmd.open");
cmd.Handler = cmdHandler;
}
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.