Page 1 of 1

Hyperlink Listener

PostPosted: Mon Nov 04, 2019 6:36 am
by DavidHMcCracken
Can anyone tell me how to register a macro to be invoked when the user clicks a hyperlink. I can't figure out who the broadcaster is. From Pitonyak I know that I can register a selection change listener with ThisComponent.getCurrentController.addSelectionChangeListener. BasicIDETools teaches how to register a clipboard listener with CreateUNOService("").setContents( CreateUNOListener("myprefix", "")) but I can't find anything that tells who the broadcaster is when the user activates a hyperlink. It would be especially useful if this registration could be not per document (i.e. ThisComponent) but for the duration of a particular library.

Re: Hyperlink Listener

PostPosted: Mon Nov 04, 2019 10:50 am
by JeJe

Re: Hyperlink Listener

PostPosted: Mon Nov 04, 2019 1:24 pm
by Villeroy
I think, David wants to intercept hyperlink clicks rather than calling macros via hyperlinks.

Re: Hyperlink Listener

PostPosted: Mon Nov 04, 2019 2:16 pm
by JeJe
MouseClickHandler and examining viewcursor?

not sure where the handler source code originated but quickly adapting:

Code: Select all   Expand viewCollapse view

Global oMouseClickHandler As Object

Sub RegisterMouseClickHandler()
   oDocView = ThisComponent.currentController
   oMouseClickHandler = _
   createUnoListener("MyAppM_", "")
   oDocView.addMouseClickHandler (oMouseClickHandler)

End Sub

Sub UnregisterMouseClickHandler()
   On Error Resume Next
   oDocView.removeMouseClickHandler (oMouseClickHandler)
   On Error GoTo 0
End Sub

Sub MyAppM_disposing(oEvt)
End Sub

Function MyAppM_mousePressed(oEvt) As Boolean

msgbox  thiscomponent.currentcontroller.viewcursor.HyperLinkURL

'from MRI
'HyperLinkEvents                  .container.XNameReplace    -INTERFACE-                   Maybevoid             48 
'HyperLinkName                    string                     ""                            Maybevoid             48 
'HyperLinkTarget                  string                     ""                            Maybevoid             48 
'HyperLinkURL                     string                     yourhyperlinkurl                          Maybevoid

MyAppM_mousePressed = False

'MyAppM_mousePressed = TRUE if handled
End Function

Function MyAppM_mouseReleased(oEvt) As Boolean
MyAppM_mouseReleased = False
'MyAppM_mouseReleased = TRUE if handled
end function

Re: Hyperlink Listener

PostPosted: Mon Nov 04, 2019 7:25 pm
by DavidHMcCracken
Thanks to both Villeroy and JeJe. As Villeroy says, I want to intercept hyperlink activation. I have developed code to provide two-way linking between plain text code editors (only for Emacs and ooBasic IDE so far) and OO Writer. The editors don't respond to hyperlinks but my macro code for them can be asynchronously invoked through a pipe. When a hyperlink is activated in a document if it is one of these special ones (there is extra information hidden in the link) I want to send my command to the selected editor, bypassing the standard link means. Mouse interception (thanks to JeJe) could be a last resort but links can also be activated from the keyboard and both of these require considerable run-time analysis to determine if a hyperlink is selected. Intercepting the hyperlink action would be simpler and more reliable. I have not gotten very far on this intercept issue. I'm not even sure that "" is the correct listener type and not knowing who the broadcaster is leaves me with no means of determining by run-time inspection of objects.