controlling 2 command bars independently

PDF-XChange Editor SDK for Developers

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

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Post Reply
AteBe
User
Posts: 63
Joined: Thu Dec 06, 2018 7:02 am

controlling 2 command bars independently

Post by AteBe »

I have 2 instances of the PDFXChange Editor embedded in an Eclipse RCP application.
As described in viewtopic.php?f=66&t=27188&p=105484&hil ... ar#p105484, I get both commandbars.

If I now hide the menubar for MainFrm (0), the menubar of the mainframe (1) will be hidden at the same time and vice versa

Code: Select all

	iControlSite = new OleControlSiteEx(frame, SWT.NONE, "PDFXEdit.PXV_Control.1");
	iControlSite.doVerb(OLE.OLEIVERB_SHOW);
	iControlSite.doVerb(OLE.OLEIVERB_UIACTIVATE);
	// Zugriff zu IPXV_Control �ber JNA
	iCtrl = new IPXV_Control(iControlSite.getPointerToUnknown());

	IPXV_MainFrame mainFrame = iCtrl.Inst().MainFrm(mainFrameIndex);
	IPXV_MainView mainView = mainFrame.View();
	IUIX_CmdBar cmdBar = mainView.CmdBar("cmdbar.menubar");
	if (pState)
	    cmdBar.Show();
	else
	    cmdBar.Hide();
However I want to control the commandbars independently.
How can I do that?
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: controlling 2 command bars independently

Post by Sasha - Tracker Dev Team »

Hello AteBe,

I have this code snippet that will add a combobox to the file submenu only to one of the two Frames:

Code: Select all

class CustomComboCommandHandler : IUIX_CmdHandler
{
	public IPXV_Inst m_Inst = null;
	public IUIX_Inst m_uiInst = null;

	public CustomComboCommandHandler(IPXV_Inst Inst)
	{
		m_Inst = Inst;
		m_uiInst = (IUIX_Inst)Inst.GetExtension("UIX");
	}

	public void OnCreateNewCtl(PDFXEdit.IUIX_Cmd pCmd, PDFXEdit.IUIX_CmdBar pParent, out PDFXEdit.IUIX_Obj pCtl)
	{
		//Here the combo box is created and initialized
		tagRECT rc;
		rc.left = 0;
		rc.right = 0;
		rc.top = 0;
		rc.bottom = 0;
		IUIX_Combo cmb = m_uiInst.CreateCombo(pParent.Obj, ref rc, m_Inst.ID2Str(pCmd.ID), (long)UIX_ComboStyleFlags.UIX_ComboStyle_Editable, null);
		cmb.InsertItem(-1, "A");
		cmb.InsertItem(-1, "B");
		cmb.InsertItem(-1, "C");
		pCtl = cmb.Obj;
	}

	public void OnGetCtlSizes(PDFXEdit.IUIX_CmdItem pItem, ref PDFXEdit.tagSIZE nSize, ref PDFXEdit.tagSIZE nMinSize, ref PDFXEdit.tagSIZE nMaxSize)
	{
		nSize.cx = 100;
		nSize.cy = pItem.Bar.Font.LineHeight + 4;
		nMaxSize.cy = nSize.cy;
	}

	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_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 (nCode == (int)UIX_NotifyCodes.UIX_Notify_SelChanged)
		{
			//Check for selection change and act accordingly
		}
	}

	public void OnDrawItemIcon(PDFXEdit.IUIX_RenderContext pRC, PDFXEdit.IUIX_CmdItem pItem, ref PDFXEdit.tagRECT stIconRect, ref PDFXEdit.tagRECT stClip)
	{

	}
}



private void addComboBoxTypeCommandToolStripMenuItem_Click(object sender, EventArgs e)
{
	pdfCtl.Inst.LockCmdCustomizationEvent();
	IUIX_Inst uiInst = (IUIX_Inst)pdfCtl.Inst.GetExtension("UIX");
	uiInst.CmdManager.LockAllPanesUpdates();

	IPXV_MainFrame firstMainFrame = pdfCtl.Inst.MainFrm[0];
	IUIX_CmdBar fileBar = firstMainFrame.View.CmdBar["cmdbar.file"];
	CustomComboCommandHandler hnd = new CustomComboCommandHandler(pdfCtl.Inst);
	IUIX_Cmd cmd = uiInst.CmdManager.CreateNewCmd("cmd.customCombo", "", hnd, null, "", 0);
	fileBar.InsertItem(cmd);


	uiInst.CmdManager.UnlockAllPanesUpdates();
	pdfCtl.Inst.UnlockCmdCustomizationEvent();
}
Try doing the proper locks/unlocks like the sample suggest and try your code.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
AteBe
User
Posts: 63
Joined: Thu Dec 06, 2018 7:02 am

Re: controlling 2 command bars independently

Post by AteBe »

Hallo Alex,
I try to use your code, but I get the following error message:

java.lang.ClassCastException: com.sun.jna.platform.win32.COM.Unknown cannot be cast to de.dpma.elsa.pdfxchange.IUIX_Inst

Code: Select all

	iControlSite = new OleControlSiteEx(frame, SWT.NONE, "PDFXEdit.PXV_Control.1");
	iControlSite.doVerb(OLE.OLEIVERB_SHOW);
	iControlSite.doVerb(OLE.OLEIVERB_UIACTIVATE);
	iCtrl = new IPXV_Control(iControlSite.getPointerToUnknown());

	IUIX_Inst uiInst = (IUIX_Inst) iCtrl.Inst().GetExtension("UIX");
Any idea why?

AteBe
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: controlling 2 command bars independently

Post by Sasha - Tracker Dev Team »

Hello AteBe,

Well, I do not write in Java. The GetExtension method will return the IUnknown interface that you will have to cast to the IUIX_Inst interface using Java conversions.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
RoGraf
User
Posts: 13
Joined: Tue Mar 20, 2018 10:39 am

Re: controlling 2 command bars independently

Post by RoGraf »

Maybe the individual Inst can be build with the pointer of the Unknown like this?

Code: Select all

	iControlSite = new OleControlSiteEx(frame, SWT.NONE, "PDFXEdit.PXV_Control.1");
	iControlSite.doVerb(OLE.OLEIVERB_SHOW);
	iControlSite.doVerb(OLE.OLEIVERB_UIACTIVATE);
	iCtrl = new IPXV_Control(iControlSite.getPointerToUnknown());

	IUIX_Inst uiInst = new IUIX_Inst( ((Unknown)iCtrl.Inst().GetExtension("UIX")).getPointer());
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: controlling 2 command bars independently

Post by Sasha - Tracker Dev Team »

Hello AteBe,

As I said before, we do not code in Java, though my colleague managed to make it working by doing this:

Code: Select all

int[] opExtIDs = gInst.getIDsOfNames(new String[] { "GetExtension", "sName"});
// prepare parameters
Variant[] name = new Variant[] { new Variant("UIX")};
// invoke method
Variant resUIX = gInst.invoke(opExtIDs[0], name, new int[] { opExtIDs[1] });
OleAutomation gUIX = resUIX.getAutomation();
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply