Customise colour dropdown

PDF-XChange Editor SDK for Developers

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

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
lidds
User
Posts: 453
Joined: Sat May 16, 2009 1:55 pm

Customise colour dropdown

Post by lidds » Wed Jun 13, 2018 2:24 pm

Within my application I am restricting the colours that the user are able to place annotations using. I like the use of the properties toolbar that appears as all modification features are there, however I would like to customise the colour dropdown to only show certain RGB colours. Is this possible, or alternatively can I replace your standard colour dropdown on the properties bar with my own?
propertiesColor.png
propertiesColor.png (16.7 KiB) Viewed 1399 times
Thanks

Simon

lidds
User
Posts: 453
Joined: Sat May 16, 2009 1:55 pm

Re: Customise colour dropdown

Post by lidds » Fri Jun 15, 2018 9:41 am

Is there any update on this?

Thanks

Simon

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

Re: Customise colour dropdown

Post by Sasha - Tracker Dev Team » Sat Jun 16, 2018 1:28 pm

Hello Simon,

Here's how you can get to the Color Picker interface (in this sample the stroke color command):

Code: Select all

class ColorPickerCommandHandler : PDFXEdit.IUIX_CmdHandler
{
	public PDFXEdit.IPXV_Inst m_Inst = null;
	public PDFXEdit.IUIX_CmdHandler m_OldHandler = null;
	public PDFXEdit.IUIX_List m_List;

	public ColorPickerCommandHandler(PDFXEdit.IPXV_Inst Inst)
	{
		m_Inst = Inst;
	}

	public void OnCreateNewCtl(PDFXEdit.IUIX_Cmd pCmd, PDFXEdit.IUIX_CmdBar pParent, out PDFXEdit.IUIX_Obj pCtl)
	{
		//Here the list is created
		m_OldHandler.OnCreateNewCtl(pCmd, pParent, out pCtl);

	}

	public void OnGetCtlSizes(PDFXEdit.IUIX_CmdItem pItem, ref PDFXEdit.tagSIZE nSize, ref PDFXEdit.tagSIZE nMinSize, ref PDFXEdit.tagSIZE nMaxSize)
	{
		m_OldHandler.OnGetCtlSizes(pItem, nSize, nMinSize, nMaxSize);
	}

	public void OnGetItemState(PDFXEdit.IUIX_Cmd pCmd, PDFXEdit.IUIX_CmdItem pItem, PDFXEdit.IUIX_Obj pOwner, out int nState)
	{
		m_OldHandler.OnGetItemState(pCmd, pItem, pOwner, out nState);

	}

	public void OnGetItemSubMenu(PDFXEdit.IUIX_CmdItem pItem, out PDFXEdit.IUIX_CmdMenu pSubMenu)
	{
		//pSubMenu = null;
		pSubMenu = pItem.SubMenu;
	}

	public void OnNotify(int nCode, PDFXEdit.IUIX_Cmd pCmd, PDFXEdit.IUIX_CmdItem pItem, PDFXEdit.IUIX_Obj pOwner, uint nNotifyData)
	{
		//Getting color picker
		IUIX_CmdColorBtn cbutton = pItem.Ctl.Impl as IUIX_CmdColorBtn;
		//cbutton.ColorPicker;
		m_OldHandler.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)
	{
		m_OldHandler.OnDrawItemIcon(pRC, pItem, stIconRect, stClip);
	}
}

private void colorPickerTestToolStripMenuItem_Click(object sender, EventArgs e)
{
	ColorPickerCommandHandler ch = new ColorPickerCommandHandler(pdfCtl.Inst);
	PDFXEdit.IUIX_Inst iuiInst = (PDFXEdit.IUIX_Inst)pdfCtl.Inst.GetExtension("UIX");
	PDFXEdit.IUIX_Cmd cmd = iuiInst.CmdManager.Cmds.Find("cmd.scolor");
	ch.m_OldHandler = cmd.Handler;
	cmd.Handler = ch;
}
After that you can for example add custom colors:

Code: Select all

public void OnNotify(int nCode, PDFXEdit.IUIX_Cmd pCmd, PDFXEdit.IUIX_CmdItem pItem, PDFXEdit.IUIX_Obj pOwner, uint nNotifyData)
{
	//Getting color picker
	IUIX_CmdColorBtn cbutton = pItem.Ctl.Impl as IUIX_CmdColorBtn;
	IAUX_Inst auxInst = (IAUX_Inst)m_Inst.GetExtension("AUX");
	PDFXEdit.IColor color = auxInst.CreateColor(PDFXEdit.ColorType.ColorType_RGB);
	color.SetRGB(1.0f, 0.0f, 0.0f);
	cbutton.ColorPicker.AddCustomColor(color);
	m_OldHandler.OnNotify(nCode, pCmd, pItem, pOwner, nNotifyData);
}
Also, do not forget to remove the Custom Command handler when destroying the form.

Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

lidds
User
Posts: 453
Joined: Sat May 16, 2009 1:55 pm

Re: Customise colour dropdown

Post by lidds » Thu Jun 21, 2018 8:49 am

Alex,

I have tried the following code, but I get the below error:

Error registering background colour events: Unable to cast object of type 'ColorPickerCommandHandler' to type 'PDFXEdit.IUIX_CmdHandler'.

On this line:

Code: Select all

cmd.Handler = ch
Full code below:

Code: Select all

Public Sub registerBGColourEvent()
        Try
            Dim ch As ColorPickerCommandHandler = New ColorPickerCommandHandler(Me.docPreview.Inst)
            Dim iuiInst As PDFXEdit.IUIX_Inst = CType(Me.docPreview.Inst.GetExtension("UIX"), PDFXEdit.IUIX_Inst)
            Dim cmd As PDFXEdit.IUIX_Cmd = iuiInst.CmdManager.Cmds.Find("cmd.scolor")
            ch.m_OldHandler = cmd.Handler
            cmd.Handler = ch
        Catch ex As Exception
            Debug.WriteLine("Error registering background colour events: " & ex.Message)
        End Try
    End Sub

    Class ColorPickerCommandHandler
        Public m_OldHandler As PDFXEdit.IUIX_CmdHandler = Nothing
        Public m_List As PDFXEdit.IUIX_List
        Public m_Inst As PDFXEdit.IPXV_Inst = Nothing

        Public Sub New(ByVal Inst As PDFXEdit.IPXV_Inst)
            m_Inst = Inst
        End Sub

        Public Sub OnCreateNewCtl(ByVal pCmd As PDFXEdit.IUIX_Cmd, ByVal pParent As PDFXEdit.IUIX_CmdBar, <Out> ByRef pCtl As PDFXEdit.IUIX_Obj)
            m_OldHandler.OnCreateNewCtl(pCmd, pParent, pCtl)
        End Sub

        Public Sub OnGetCtlSizes(ByVal pItem As PDFXEdit.IUIX_CmdItem, ByRef nSize As PDFXEdit.tagSIZE, ByRef nMinSize As PDFXEdit.tagSIZE, ByRef nMaxSize As PDFXEdit.tagSIZE)
            m_OldHandler.OnGetCtlSizes(pItem, nSize, nMinSize, nMaxSize)
        End Sub

        Public Sub OnGetItemState(ByVal pCmd As PDFXEdit.IUIX_Cmd, ByVal pItem As PDFXEdit.IUIX_CmdItem, ByVal pOwner As PDFXEdit.IUIX_Obj, <Out> ByRef nState As Integer)
            m_OldHandler.OnGetItemState(pCmd, pItem, pOwner, nState)
        End Sub

        Public Sub OnGetItemSubMenu(ByVal pItem As PDFXEdit.IUIX_CmdItem, <Out> ByRef pSubMenu As PDFXEdit.IUIX_CmdMenu)
            pSubMenu = pItem.SubMenu
        End Sub

        Public Sub OnNotify(ByVal nCode As Integer, ByVal pCmd As PDFXEdit.IUIX_Cmd, ByVal pItem As PDFXEdit.IUIX_CmdItem, ByVal pOwner As PDFXEdit.IUIX_Obj, ByVal nNotifyData As UInteger)
            Dim cbutton As IUIX_CmdColorBtn = TryCast(pItem.Ctl.Impl, IUIX_CmdColorBtn)
            m_OldHandler.OnNotify(nCode, pCmd, pItem, pOwner, nNotifyData)
        End Sub

        Public Sub OnDrawItemIcon(ByVal pRC As PDFXEdit.IUIX_RenderContext, ByVal pItem As PDFXEdit.IUIX_CmdItem, ByRef stIconRect As PDFXEdit.tagRECT, ByRef stClip As PDFXEdit.tagRECT)
            m_OldHandler.OnDrawItemIcon(pRC, pItem, stIconRect, stClip)
        End Sub
    End Class

    Private Sub colorPickerTestToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim ch As ColorPickerCommandHandler = New ColorPickerCommandHandler(Me.docPreview.Inst)
        Dim iuiInst As PDFXEdit.IUIX_Inst = CType(Me.docPreview.Inst.GetExtension("UIX"), PDFXEdit.IUIX_Inst)
        Dim cmd As PDFXEdit.IUIX_Cmd = iuiInst.CmdManager.Cmds.Find("cmd.scolor")
        ch.m_OldHandler = cmd.Handler
        cmd.Handler = ch
    End Sub

    Public Sub OnNotify(ByVal nCode As Integer, ByVal pCmd As PDFXEdit.IUIX_Cmd, ByVal pItem As PDFXEdit.IUIX_CmdItem, ByVal pOwner As PDFXEdit.IUIX_Obj, ByVal nNotifyData As UInteger)
        Dim cbutton As IUIX_CmdColorBtn = TryCast(pItem.Ctl.Impl, IUIX_CmdColorBtn)
        Dim auxInst As IAUX_Inst = CType(Me.docPreview.Inst.GetExtension("AUX"), IAUX_Inst)
        Dim color As PDFXEdit.IColor = auxInst.CreateColor(PDFXEdit.ColorType.ColorType_RGB)
        color.SetRGB(1.0F, 0.0F, 0.0F)
        cbutton.ColorPicker.AddCustomColor(color)
        myEventBGColourTarget.m_OldHandler.OnNotify(nCode, pCmd, pItem, pOwner, nNotifyData)
    End Sub
Obviously doing something wrong here

Thanks

Simon

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

Re: Customise colour dropdown

Post by Sasha - Tracker Dev Team » Thu Jun 21, 2018 11:32 am

Hello Simon,

I'm not a VB expert but obviously you've forgot to inherit your class:

Code: Select all

class ColorPickerCommandHandler : PDFXEdit.IUIX_CmdHandler
Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

lidds
User
Posts: 453
Joined: Sat May 16, 2009 1:55 pm

Re: Customise colour dropdown

Post by lidds » Mon Jan 07, 2019 3:27 pm

Alex,

I have got this working now and the color is being successfully added to the color picker. However the problem is that I now wish to hide the "Standard Colors" and also the "More Colors" button from the colorPicker. I have added my code below for info purposes:

Code: Select all

  Public Sub OnNotify(ByVal nCode As Integer, ByVal pCmd As PDFXEdit.IUIX_Cmd, ByVal pItem As PDFXEdit.IUIX_CmdItem, ByVal pOwner As PDFXEdit.IUIX_Obj, ByVal nNotifyData As UInteger)
      Dim cbutton As IUIX_CmdColorBtn = TryCast(pItem.Ctl.Impl, IUIX_CmdColorBtn)

      Dim auxInst As IAUX_Inst = CType(Me.docPreview.Inst.GetExtension("AUX"), IAUX_Inst)
      Dim color As PDFXEdit.IColor = auxInst.CreateColor(PDFXEdit.ColorType.ColorType_RGB)
      color.Value = "rgbd(" & activeAnnotColour.R.ToString & "," & activeAnnotColour.G.ToString & "," & activeAnnotColour.B.ToString & ")"

      cbutton.ColorPicker.ClearCustomColors()
      cbutton.ColorPicker.AddCustomColor(color)

      ' Add white
      color.Value = "rgbd(255,255,255)"
      cbutton.ColorPicker.AddCustomColor(color)

    myEventBGColourTarget.m_OldHandler.OnNotify(nCode, pCmd, pItem, pOwner, nNotifyData)
  End Sub

colorPicker.png
Thanks

Simon

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

Re: Customise colour dropdown

Post by Sasha - Tracker Dev Team » Tue Jan 08, 2019 8:44 am

Hello Simon,

If you are initializing the ColorPickerCommandHandler before the first stroke color popup is shown (for example, after the control initialization), then this code should work perfectly for you:

Code: Select all

public void OnCreateNewCtl(PDFXEdit.IUIX_Cmd pCmd, PDFXEdit.IUIX_CmdBar pParent, out PDFXEdit.IUIX_Obj pCtl)
{
	m_OldHandler.OnCreateNewCtl(pCmd, pParent, out pCtl);
	IntPtr outPtr;
	pCtl.QueryImpl(typeof(PDFXEdit.IUIX_CmdColorBtn).GUID, null, out outPtr);
	PDFXEdit.IUIX_CmdColorBtn cbutton = (PDFXEdit.IUIX_CmdColorBtn)System.Runtime.InteropServices.Marshal.GetObjectForIUnknown(outPtr);
	cbutton.ColorPicker.Obj.SetStyle((uint)UIX_ColorPickerStyleFlags.UIX_ColorPickerStyle_NoMoreColors | (uint)UIX_ColorPickerStyleFlags.UIX_ColorPickerStyle_NoStdColors, (uint)UIX_ColorPickerStyleFlags.UIX_ColorPickerStyle_NoMoreColors | (uint)UIX_ColorPickerStyleFlags.UIX_ColorPickerStyle_NoStdColors);
	IAUX_Inst auxInst = (IAUX_Inst)m_Inst.GetExtension("AUX");
	PDFXEdit.IColor color = auxInst.CreateColor(PDFXEdit.ColorType.ColorType_RGB);
	color.SetRGB(1.0f, 0.0f, 0.0f);
	cbutton.ColorPicker.AddCustomColor(color);
	color.SetRGB(1.0f, 0.0f, 1.0f);
	cbutton.ColorPicker.AddCustomColor(color);
	color.SetRGB(1.0f, 1.0f, 1.0f);
	cbutton.ColorPicker.AddCustomColor(color);
}
Also, there won't be any need to add any new code to the OnNotify method:

Code: Select all

public void OnNotify(int nCode, PDFXEdit.IUIX_Cmd pCmd, PDFXEdit.IUIX_CmdItem pItem, PDFXEdit.IUIX_Obj pOwner, uint nNotifyData)
{
	m_OldHandler.OnNotify(nCode, pCmd, pItem, pOwner, nNotifyData);
}
Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

lidds
User
Posts: 453
Joined: Sat May 16, 2009 1:55 pm

Re: Customise colour dropdown

Post by lidds » Tue Jan 08, 2019 10:06 am

Thanks Alex,

Worked perfectly.

Thanks for your help

Simon

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

Re: Customise colour dropdown

Post by Sasha - Tracker Dev Team » Tue Jan 08, 2019 10:12 am

:)
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

Post Reply