Hyperlink Listener

The Application Programming Interface and the OASIS Open Document Format

Hyperlink Listener

Postby DavidHMcCracken » Mon Nov 04, 2019 6:36 am

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 Nov 04, 2019 6:46 pm, edited 1 time in total.
W10 Libre 6.1.5.2 and Ubuntu-Mate 18.04 Libre 6.0.7.3
DavidHMcCracken
 
Posts: 31
Joined: Tue Apr 10, 2018 6:15 am

Re: Hyperlink Listener

Postby JeJe » Mon Nov 04, 2019 10:50 am

Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1142
Joined: Wed Mar 09, 2016 2:40 pm

Re: Hyperlink Listener

Postby Villeroy » Mon Nov 04, 2019 1:24 pm

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, no OpenOffice, LibreOffice 6.4
User avatar
Villeroy
Volunteer
 
Posts: 28538
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Hyperlink Listener

Postby JeJe » Mon Nov 04, 2019 2:16 pm

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_", "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



Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1142
Joined: Wed Mar 09, 2016 2:40 pm

Re: Hyperlink Listener

Postby DavidHMcCracken » Mon Nov 04, 2019 7:25 pm

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
DavidHMcCracken
 
Posts: 31
Joined: Tue Apr 10, 2018 6:15 am


Return to UNO API and ODF

Who is online

Users browsing this forum: No registered users and 2 guests