Page 1 of 1
Override contextMenu...
Posted: Mon Jun 19, 2017 7:58 am
by lidds
Could you please give me some example code as to how to override the page contextMenu, as shown in attached image.
I have tried the following, but got an error and I can't seem to find an override for the event.
Code: Select all
Private Sub docPreview_MouseClick(sender As Object, e As MouseEventArgs) Handles docPreview.MouseClick
If e.Button = Windows.Forms.MouseButtons.Right Then
Me.RadialMenu1.ShowPopup(New Point(e.X, e.Y))
End If
End Sub
Thanks
Simon
Re: Override contextMenu...
Posted: Mon Jun 19, 2017 8:01 am
by Sasha - Tracker Dev Team
Hello Simon,
Please check this topic:
https://www.pdf-xchange.com/forum3 ... 66&t=26300
Cheers,
Alex
Re: Override contextMenu...
Posted: Mon Jun 19, 2017 8:15 am
by lidds
Alex,
Thank you for the link, I did see this however I am writing in VB.Net and was unable to convert the code. To be honest, my main issue is that I am struggling with the whole concept of how your API code is working, mainly because I am new to coding and use to working with .NET API's instead of COM.
What I basically want to do is replace your contextMenu with my own.
Thanks
Simon
Re: Override contextMenu...
Posted: Mon Jun 19, 2017 8:38 am
by Sasha - Tracker Dev Team
Hello Simon,
Well the code in that topic does precisely what you need - gets the current menu that you can modify as you like. Basically you will have to check whether it's a PagesView menu and then update it's items.
Here's the sample that would work in FullDemo:
Code: Select all
if (e.nEventID == nIDS[(int)IDS.e_beforeShowContextMenu])
{
PDFXEdit.IPXV_BeforeShowContextMenuEvent evt = (PDFXEdit.IPXV_BeforeShowContextMenuEvent)e.pEvent;
int nID = pdfCtl.Inst.Str2ID("menu.pagesView", false);
if (evt.MenuID == nID)
{
//e.pEvent.Handled = true;
}
}
Cheers,
Alex
Re: Override contextMenu...
Posted: Mon Jun 19, 2017 9:08 am
by lidds
Thanks Alex,
This is work now, however, it seems to only hide the menu if the cursor is of a hand type. If I clicked to draw a line and then right clicked on the page (not over any annotation) it brings up the menu. If I then switch back to hand mode the menu is hidden again. Any ideas?
Also how can I get the cursor location so I can show my menubar, as the IPXV_ControlEvents_OnEventEvent does not pass cursor position, therefore unable to use e.X or e.Y?
Code: Select all
Me.RadialMenu1.ShowPopup(New Point(e.X, e.Y))
Thanks for all your help
Simon
Re: Override contextMenu...
Posted: Mon Jun 19, 2017 9:12 am
by Sasha - Tracker Dev Team
Hello Simon,
Please debug and check the menu ID's - different tools have different menus - you will have to override them all.
Cheers,
Alex
Re: Override contextMenu...
Posted: Mon Jun 19, 2017 9:19 am
by lidds
OK, will do, thanks Alex.
However how do I get the cursor position?
Thanks
Simon
Re: Override contextMenu...
Posted: Mon Jun 19, 2017 9:26 am
by Sasha - Tracker Dev Team
Hello Simon,
Check out this post:
https://forum.pdf-xchange.com/ ... et#p113878
Cheers,
Alex
Re: Override contextMenu...
Posted: Mon Jun 19, 2017 9:29 am
by lidds
Great thanks Alex,
I just want to check that I am OK to use the actual menu ID's in my code and these do not change from build to build?
Thanks
Re: Override contextMenu...
Posted: Mon Jun 19, 2017 11:54 am
by Sasha - Tracker Dev Team
Hello Simon,
Never use numeric ID representations - use only the IDs that are converted from their string representations on the go (for example like the ID array is being filled in the FullDemo application at the beginning of program). The string IDs won't be changed from build to build.
Cheers,
Alex
Re: Override contextMenu...
Posted: Tue Jun 20, 2017 12:43 am
by lidds
Thanks Alex,
In that case can you please let me know where all the string values are documented e.g. like the one you used in your example "menu.pagesview"
Thanks
Simon
Re: Override contextMenu...
Posted: Tue Jun 20, 2017 9:12 am
by Sasha - Tracker Dev Team
Hello Simon,
The FullDemo application holds pretty much all the IDs that you will require - so please do look them up there.
Cheers,
Alex
Re: Override contextMenu...
Posted: Mon Jun 26, 2017 8:41 am
by lidds
Alex,
I have had a look at the link you gave me in the previous post to get the cursor position, however I am unable to get this to work. After converting the code into vb.Net the following lines gives errors:
Code: Select all
Implements PDFXEdit.IUIX_ObjImpl
Implements IDisposable
I have attached a sample project and I was wondering if you may be able to assist me with getting this to work.
Thanks in advance
Simon
Re: Override contextMenu...
Posted: Mon Jun 26, 2017 12:43 pm
by Sasha - Tracker Dev Team
Hello Simon,
I'm not a VB.Net expert, but here's the solution:
Capture.PNG
Cheers,
Alex
Re: Override contextMenu...
Posted: Thu Jun 29, 2017 12:51 pm
by lidds
Thanks Alex,
I have got this working now using the following code, however I do now have an issue regarding the cursor coordinates being offset depending if I have a docked pane in PDF Xchange. Please see attached screen shot for more detailed explanation.
Code: Select all
Public Sub OnEvent(pSender As PDFXEdit.IUIX_Obj, pEvent As PDFXEdit.IUIX_Event) Implements PDFXEdit.IUIX_ObjImpl.OnEvent
If pEvent.Code = CInt(&H204) Then
Dim pt As PDFXEdit.tagPOINT
pt.x = pEvent.Pos.x
pt.y = pEvent.Pos.y
Dim nHitTestCode As Integer = 0
Dim annot As PDFXEdit.IPXC_Annotation = Parent.docPreview.Doc.ActiveView.PagesView.GetAnnotFromPt(pt, nHitTestCode)
If annot IsNot Nothing Then
'Getting atom from IPXS_Inst
Dim linkAnnotType As UInteger = Parent.pxsInst.StrToAtom("Link")
If annot.Type = linkAnnotType Then
'If there are any invalid paths then we mark event as handled and this will not execute link action
pEvent.Handled = True
End If
Else
Parent.RadialMenu1.ShowPopup(Parent.docPreview.PointToScreen(New Point(pEvent.Pos.x, pEvent.Pos.y)))
End If
ElseIf pEvent.Code = CInt(PDFXEdit.UIX_EventCodes.e_BeforeDestroy) Then
Dispose()
ElseIf pEvent.Code = CInt(PDFXEdit.UIX_EventCodes.e_Last) Then
Dispose()
End If
End Sub
cursor pos with docked pane.png
Thanks in advance
Simon
Re: Override contextMenu...
Posted: Fri Jun 30, 2017 2:20 pm
by Sasha - Tracker Dev Team
Hello Simon,
The coordinates that you have here are in the PagesView coordinates system. You will need to transform them into Screen coordinates.This method transforms Screen coordinates into PagesView coordinate system:
https://sdkhelp.pdf-xchange.com/vie ... PtToClient
And this one does vice-versa:
https://sdkhelp.pdf-xchange.com/vie ... PtToScreen
Cheers,
Alex
Re: Override contextMenu...
Posted: Mon Jul 03, 2017 11:11 pm
by lidds
Thanks this worked
Re: Override contextMenu...
Posted: Tue Jul 04, 2017 5:16 am
by Sasha - Tracker Dev Team
Re: Override contextMenu...
Posted: Tue Aug 29, 2017 11:52 am
by lidds
Alex,
I have just noticed something with my code for my custom contextmenu.
1. If I right click on the document NOT over any annotation, my contextmenu is displayed. This is CORRECT
2. If I right click over some annotation that is selected then the below menu is displayed. This is CORRECT
contextMenuAnnoSelected.png
3. If I right click over some annotation that is NOT selected then the below menu is displayed. I do not want to display this menu, but the menu from option 2.
ContextMenuNoAnnoSelected.png
4. If I right click on the annotation element in the comment pane then my menu is displayed. I do not want this, I want to display your standard annotation menu.
RightClickCommentPane.png
Below is the code that I am using, could you please assist me with trying to acheive this.
Code: Select all
Public Sub OnEvent(pSender As PDFXEdit.IUIX_Obj, pEvent As PDFXEdit.IUIX_Event) Implements PDFXEdit.IUIX_ObjImpl.OnEvent
If pEvent.Code = CInt(&H204) Then
Dim pt As PDFXEdit.tagPOINT
pt.x = pEvent.Pos.x
pt.y = pEvent.Pos.y
Dim screenPt As PDFXEdit.tagPOINT
Dim nHitTestCode As Integer = 0
Dim annot As PDFXEdit.IPXC_Annotation = Parent.docPreview.Doc.ActiveView.PagesView.GetAnnotFromPt(pt, nHitTestCode)
If annot IsNot Nothing Then
pEvent.Handled = True
Else
pSender.ClientPtToScreen(pt, screenPt)
' Custom context menu
Parent.RadialMenu1.ShowPopup(New Point(screenPt.x, screenPt.y))
End If
End If
End Sub
Thanks in advance
Simon
Re: Override contextMenu...
Posted: Tue Aug 29, 2017 12:55 pm
by Sasha - Tracker Dev Team
Hello Simon,
As for the 3, you are putting the event handled as True, meaning that all other listeners won't correspond - that's why the annotation is not selected (as the Editor does by default).
As for the 4, what object exactly have you implemented the handler for?
Cheers,
Alex
Re: Override contextMenu...
Posted: Tue Aug 29, 2017 1:06 pm
by lidds
Alex,
I have changed the pevent to False and this has solved that issue.
With regards to 4, please see more complete code
Code: Select all
Public myEventTarget As CustomEventTarget = Nothing
...
Public Sub registerMouseEvent()
Try
myEventTarget = New CustomEventTarget(Me.docPreview.Doc.ActiveView.PagesView.Obj, Me)
Catch ex As Exception
Console.WriteLine("Error registering mouse events: " & ex.Message)
End Try
End Sub
Partial Public Class CustomEventTarget
Implements PDFXEdit.IUIX_ObjImpl
Implements IDisposable
'Here we push custom implementation of the PagesView
Public Sub New(obj As PDFXEdit.IUIX_Obj, parentForm As frmDocDesigner)
Obj_ = obj
If Obj_ IsNot Nothing Then
Obj_.PushImpl(Me)
End If
Parent = parentForm
End Sub
Protected Overrides Sub Finalize()
Try
Dispose()
Finally
MyBase.Finalize()
End Try
End Sub
'Main form - a parent that in our case holds the PDFXEdit control
Public Parent As frmDocDesigner = Nothing
'Object for which we are implementing the custom event listener
Public Obj_ As PDFXEdit.IUIX_Obj
'Used for single dispose control
Private Disposed_ As Boolean = False
' Holds cursor postion
Public cursorX As Integer = 0
Public cursorY As Integer = 0
' IUIX_ObjImpl
Public ReadOnly Property Obj() As PDFXEdit.IUIX_Obj
Get
Return Me.Obj_
End Get
End Property
'Event listener that listens for all of the needed events
Public Sub OnEvent(pSender As PDFXEdit.IUIX_Obj, pEvent As PDFXEdit.IUIX_Event) Implements PDFXEdit.IUIX_ObjImpl.OnEvent
'Console.WriteLine("Event Code: " & pEvent.Code.ToString)
If pEvent.Code = CInt(&H204) Then
Dim pt As PDFXEdit.tagPOINT
pt.x = pEvent.Pos.x
pt.y = pEvent.Pos.y
Dim screenPt As PDFXEdit.tagPOINT
Dim nHitTestCode As Integer = 0
Dim annot As PDFXEdit.IPXC_Annotation = Parent.docPreview.Doc.ActiveView.PagesView.GetAnnotFromPt(pt, nHitTestCode)
If annot IsNot Nothing Then
pEvent.Handled = False
Else
pSender.ClientPtToScreen(pt, screenPt)
' Only shows annotation radial menu if PDF viewer is not in View Only mode
If MISData.Instance.ViewerMode <> "View" Then
Parent.RadialMenu1.ShowPopup(New Point(screenPt.x, screenPt.y))
End If
End If
End Sub
End Class
Thanks in advance
Simon
Re: Override contextMenu...
Posted: Thu Aug 31, 2017 9:11 am
by lidds
Alex,
I know your forum has been down for a day but I was wondering if you had a chance to take a look at this?
Thanks
Simon
Re: Override contextMenu...
Posted: Thu Aug 31, 2017 9:16 am
by Sasha - Tracker Dev Team
Hello Simon,
What I see from your code is that you are handling the pages view's object - it shouldn't behave like that in the comments panel. Are you catching the RMB click event in the comments panel?
Cheers,
Alex
Re: Override contextMenu...
Posted: Thu Aug 31, 2017 9:54 am
by lidds
Alex,
I have just checked my code and I am not capturing RMB anywhere else. If I changed the code to the following, e.g. disabled my custom menu it all works fine with the expected contextmenu.
As a work around, can I somehow get the screen region of document view area and compare with my cursor point, if the cursor point is not in the document view region then assume it is in a pane and then I could execute pEvent.Handled = False and not show my menu?
Code: Select all
Public Sub OnEvent(pSender As PDFXEdit.IUIX_Obj, pEvent As PDFXEdit.IUIX_Event) Implements PDFXEdit.IUIX_ObjImpl.OnEvent
'Console.WriteLine("Event Code: " & pEvent.Code.ToString)
If pEvent.Code = CInt(&H204) Then
Console.WriteLine("Event Code: " & pEvent.Code)
Dim pt As PDFXEdit.tagPOINT
pt.x = pEvent.Pos.x
pt.y = pEvent.Pos.y
Dim screenPt As PDFXEdit.tagPOINT
Dim nHitTestCode As Integer = 0
Dim annot As PDFXEdit.IPXC_Annotation = Parent.docPreview.Doc.ActiveView.PagesView.GetAnnotFromPt(pt, nHitTestCode)
If annot IsNot Nothing Then
pEvent.Handled = False
Else
pSender.ClientPtToScreen(pt, screenPt)
' Only shows annotation radial menu if PDF viewer is not in View Only mode
If MISData.Instance.ViewerMode <> "View" Then
'Parent.RadialMenu1.ShowPopup(New Point(screenPt.x, screenPt.y))
pEvent.Handled = False
End If
End If
Re: Override contextMenu...
Posted: Thu Aug 31, 2017 1:51 pm
by lidds
Was just wondering if you think this is possible?
Thanks
Simon
Re: Override contextMenu...
Posted: Thu Aug 31, 2017 2:50 pm
by Sasha - Tracker Dev Team
Hello Simon,
It is possible, though the RMB event shouldn't be called when you click on the Comments Panel - that's the strange issue.
Cheers,
Alex
Re: Override contextMenu...
Posted: Thu Aug 31, 2017 3:04 pm
by lidds
Alex,
It is definately something in this code below, as if I comment it out as shown then the menubars work fine.
Just for your information if I right click on a annotation in the comment pane then the annot variable is coming back as Nothing, which is correct, however it will always hit my custom contextmenu if this is the case.
Code: Select all
If pEvent.Code = CInt(&H204) Then
Console.WriteLine("Event Code: " & pEvent.Code)
Dim pt As PDFXEdit.tagPOINT
pt.x = pEvent.Pos.x
pt.y = pEvent.Pos.y
Dim screenPt As PDFXEdit.tagPOINT
Dim nHitTestCode As Integer = 0
Dim annot As PDFXEdit.IPXC_Annotation = Parent.docPreview.Doc.ActiveView.PagesView.GetAnnotFromPt(pt, nHitTestCode)
If annot IsNot Nothing Then
pEvent.Handled = False
Else
'pSender.ClientPtToScreen(pt, screenPt)
'' Only shows annotation radial menu if PDF viewer is not in View Only mode
'If MISData.Instance.ViewerMode <> "View" Then
' Parent.RadialMenu1.ShowPopup(New Point(screenPt.x, screenPt.y))
'End If
End If
Thanks
Simon
Re: Override contextMenu...
Posted: Fri Sep 01, 2017 8:32 am
by lidds
Alex,
You were correct I had custom events registerd against the comment pane.
Sorry for the wasted time
Thanks
Simon
Re: Override contextMenu...
Posted: Fri Sep 01, 2017 8:48 am
by Tracker Supp-Stefan
Hi Simon,
Glad to hear you figured out what was causing this!
We will consider this one resoved now!
Cheers,
Stefan