Hyperlink Listener

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
DavidHMcCracken
Posts: 44
Joined: Tue Apr 10, 2018 6:15 am

Hyperlink Listener

Post 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("com.sun.star.datatransfer.clipboard.SystemClipboard").setContents( CreateUNOListener("myprefix", "com.sun.star.datatransfer.XTransferable")) 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.
Last edited by DavidHMcCracken on Mon Jan 25, 2021 7:53 pm, edited 3 times in total.
W10 Libre 6.1.5.2 and Ubuntu-Mate 18.04 Libre 6.0.7.3
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: Hyperlink Listener

Post by JeJe »

Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Hyperlink Listener

Post by Villeroy »

I think, David wants to intercept hyperlink clicks rather than calling macros via hyperlinks.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: Hyperlink Listener

Post by JeJe »

MouseClickHandler and examining viewcursor?

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

Code: Select all


Global oMouseClickHandler As Object

Sub RegisterMouseClickHandler()
	oDocView = ThisComponent.currentController
	oMouseClickHandler = _
	createUnoListener("MyAppM_", "com.sun.star.awt.XMouseClickHandler")
	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



Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
DavidHMcCracken
Posts: 44
Joined: Tue Apr 10, 2018 6:15 am

Re: Hyperlink Listener

Post 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 "com.sun.star.awt.XActionListener" 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.
W10 Libre 6.1.5.2 and Ubuntu-Mate 18.04 Libre 6.0.7.3
Post Reply