I didn’t find the names of macros assigned to buttons via XRay, so I tried to got it directly from content.xml (ODT is renamed ZIP mainly with XMLs)
But the true is, the ODT’s XMLs have very complicated structure and I tested it only with one small ODS test.ods (10.6 kB)
.
Sub getButtonMacrosFromInnerXML 'get the macros assigned to buttons in ODS; source: https://ask.libreoffice.org/t/is-it-possible-to-view-and-modify-with-starbasic-xml-opendocument-code-of-current-document-writer/80798/11
dim oDoc as object, oContent as object, oXML as object, oDOM as object, oXMLbutton as object, o as object, i&, j&, k&, s$, oButton as object, oEvents as object, oEvent as object, _
ss$
oDoc=ThisComponent
oContent=getZipContentAsByteArray(oDoc, "content.xml")
'msgbox "content.xml len: " & ubound(oContent)
'msgbox getTextInputStreamFromByteArray(oContent).readString(array(), true)
oXML=createUnoService("com.sun.star.xml.dom.DocumentBuilder")
oDOM=oXML.parse(getTextInputStreamFromByteArray(oContent))
oXMLbutton=oDOM.getElementsByTagName("button")
if oXMLbutton.Length>0 then 'there is some button
for i=0 to oXMLbutton.Length-1
oButton=oXMLbutton.item(i) 'current button
oEvents=oButton.getElementsByTagName("event-listeners")
if oEvents.Length>0 then 'button has macro(s)
s=s & oButton.getAttribute("name") & chr(13)
for j=0 to oEvents.Length-1
oEvent=oEvents.item(0).getElementsByTagName("event-listener") 'single event
if oEvent.Length>0 then
for k=0 to oEvent.Length-1
o=oEvent.item(k)
'msgbox getXMLString(o)
ss=o.getAttribute("event-name")
s=s & chr(9) & Mid(ss, InStr(ss, ":")+1) & " : "
ss=o.getAttribute("href")
ss=Mid(ss, InStr(ss, ":")+1)
ss=Left(ss, InStr(ss, "?")-1)
s=s & chr(9) & ss
s=s & chr(13)
next k
end if
next j
end if
s=s & chr(13)
next i
end if
msgbox s
End Sub
Function getZipContentAsByteArray(oDoc as object, sFile$) as object
dim oZIP as object, oStorage as object, oStream as object, oContent as object, iLen&, iSuccess&, _
storeProps(0) as new com.sun.star.beans.PropertyValue, args(1) as object
oStorage=createUnoService("com.sun.star.embed.StorageFactory").createInstance
oStream=oStorage.openStreamElement("zipStream", com.sun.star.embed.ElementModes.READWRITE)
storeProps(0).Name="OutputStream" : storeProps(0).Value=oStream
oDoc.storeToUrl("private:stream", storeProps)
args(0)=oStream
oZIP=createUnoService("com.sun.star.packages.zip.ZipFileAccess")
oZIP.initialize(args)
oContent=oZIP.getByname(sFile)
iLen=oContent.available()
dim aByte(iLen) as byte
iSuccess=oContent.readBytes(aByte, iLen)
if iSuccess<>iLen then
msgbox "bug"
exit Function
endif
getZipContentAsByteArray=aByte
End Function
Function getTextInputStreamFromByteArray(aByte) as object
dim oPipe as object, oStream as object
oPipe=createUnoService("com.sun.star.io.Pipe")
oStream=createUnoService("com.sun.star.io.TextInputStream")
oStream.setInputStream(oPipe)
with oPipe
.writeBytes(aByte)
.closeOutput()
end with
getTextInputStreamFromByteArray=oStream
End Function
Function getXMLString(oXMLelement as object) as string
dim oDocumentBuilder as object, oDOMdocumentNew as object, oXMLelementNew as object, oPipe as object, oStream as object, sXML$
oDocumentBuilder=createUnoService("com.sun.star.xml.dom.DocumentBuilder")
oDOMdocumentNew=oDocumentBuilder.newDocument()
oXMLelementNew=oDOMdocumentNew.importNode(oXMLelement, true)
oDOMdocumentNew.appendChild(oXMLelementNew)
oPipe=createUnoService("com.sun.star.io.Pipe")
oStream=createUnoService("com.sun.star.io.TextInputStream")
oStream.setInputStream(oPipe)
with oDOMdocumentNew
.setOutputStream(oPipe)
.start()
end with
oPipe.closeOutput()
sXML=oStream.readString(array(), true)
getXMLString=sXML
End Function