Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class PdfEditorCommandHandler : PDFXEdit.IUIX_CmdHandler
{
public PDFXEdit.IPXV_Inst m_Inst = null;
public PDFXEdit.IUIX_CmdHandler m_OldSaveHandler = null;
public PDFXEdit.IUIX_CmdHandler m_OldSaveAsHandler = null;
private long m_nSaveID = 0;
private long m_nSaveAsID = 0;
public PdfEditorCommandHandler(PDFXEdit.IPXV_Inst Inst)
{
m_Inst = Inst;
m_nSaveID = m_Inst.Str2ID("cmd.save");
m_nSaveAsID = m_Inst.Str2ID("cmd.saveAs");
}
public void OnCreateNewCtl(PDFXEdit.IUIX_Cmd pCmd, PDFXEdit.IUIX_CmdBar pParent, out PDFXEdit.IUIX_Obj pCtl)
{
if (pCmd.ID == m_nSaveID)
m_OldSaveHandler.OnCreateNewCtl(pCmd, pParent, out pCtl);
else if (pCmd.ID == m_nSaveAsID)
m_OldSaveAsHandler.OnCreateNewCtl(pCmd, pParent, out pCtl);
else
pCtl = null;
}
public void OnGetCtlSizes(PDFXEdit.IUIX_CmdItem pItem, ref PDFXEdit.tagSIZE nSize, ref PDFXEdit.tagSIZE nMinSize, ref PDFXEdit.tagSIZE nMaxSize)
{
if (pItem.Cmd.ID == m_nSaveID)
m_OldSaveHandler.OnGetCtlSizes(pItem, nSize, nMinSize, nMaxSize);
else if (pItem.Cmd.ID == m_nSaveAsID)
m_OldSaveAsHandler.OnGetCtlSizes(pItem, nSize, nMinSize, nMaxSize);
}
public void OnGetItemState(PDFXEdit.IUIX_Cmd pCmd, PDFXEdit.IUIX_CmdItem pItem, PDFXEdit.IUIX_Obj pOwner, out int nState)
{
if (pCmd.ID == m_nSaveID)
m_OldSaveHandler.OnGetItemState(pCmd, pItem, pOwner, out nState);
else if (pCmd.ID == m_nSaveAsID)
m_OldSaveAsHandler.OnGetItemState(pCmd, pItem, pOwner, out nState);
else
nState = (int)PDFXEdit.UIX_CmdItemState.UIX_CmdItemState_Unknown;
}
public void OnGetItemSubMenu(PDFXEdit.IUIX_CmdItem pItem, out PDFXEdit.IUIX_CmdMenu pSubMenu)
{
//pSubMenu = pItem.SubMenu;
if (pItem.Cmd.ID == m_nSaveID)
m_OldSaveHandler.OnGetItemSubMenu(pItem, out pSubMenu);
else if (pItem.Cmd.ID == m_nSaveAsID)
m_OldSaveAsHandler.OnGetItemSubMenu(pItem, out pSubMenu);
else
pSubMenu = pItem.SubMenu;
}
public void OnNotify(int nCode, PDFXEdit.IUIX_Cmd pCmd, PDFXEdit.IUIX_CmdItem pItem, PDFXEdit.IUIX_Obj pOwner, uint nNotifyData)
{
if (pCmd.ID == m_nSaveID)
{
//...
//Save notification
//...
m_OldSaveHandler.OnNotify(nCode, pCmd, pItem, pOwner, nNotifyData);
}
else if (pCmd.ID == m_nSaveAsID)
{
//...
//Save As notification
//...
m_OldSaveAsHandler.OnNotify(nCode, pCmd, pItem, pOwner, nNotifyData);
}
}
public void OnDrawItemIcon(PDFXEdit.IUIX_RenderContext pRC, PDFXEdit.IUIX_CmdItem pItem, ref PDFXEdit.tagRECT stIconRect, ref PDFXEdit.tagRECT stClip)
{
//throw new System.NotImplementedException();
if (pItem.Cmd.ID == m_nSaveID)
m_OldSaveHandler.OnDrawItemIcon(pRC, pItem, stIconRect, stClip);
else if (pItem.Cmd.ID == m_nSaveAsID)
m_OldSaveAsHandler.OnDrawItemIcon(pRC, pItem, stIconRect, stClip);
}
}
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.save");
cmdHandler.m_OldSaveHandler = cmd.Handler;
cmd.Handler = cmdHandler;
cmd = iuiInst.CmdManager.Cmds.Find("cmd.saveAs");
cmdHandler.m_OldSaveAsHandler = cmd.Handler;
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.