Thanks for the replies.
This may be wrong, but the answer seems to be to use XCloseListener - but it can't be done in Basic because Basic does not support exceptions. The XTerminateListener has the same problem.
https://wiki.openoffice.org/wiki/Docume ... n_Handling
This page suggests another way, which is to use registerDispatchProviderInterceptor
http://openoffice.2283327.n4.nabble.com ... 70531.html
Pitonyak's OpenOffice.org Macros Explained has a listing for this but modifying it for the close events doesn't work either.
Code: Select all
Global oDispatchInterceptor
Global oSlaveDispatchProvider
Global oMasterDispatchProvider
Global oFrame
Global bDebug As Boolean
Dim oCopyDispatch
Sub RegisterInterceptor
oFrame = ThisComponent.currentController.Frame
oDispatchInterceptor = CreateUnoListener("ThisFrame_", _
"com.sun.star.frame.XDispatchProviderInterceptor")
oFrame.registerDispatchProviderInterceptor(oDispatchInterceptor)
'ThisComponent.currentController.Frame.close(true)
End Sub
Sub ReleaseInterceptor()
On Error Resume Next
oFrame.releaseDispatchProviderInterceptor(oDispatchInterceptor)
End Sub
Function ThisFrame_queryDispatch ( oUrl, _
sTargetFrameName As String, lSearchFlags As Long ) As Variant
302
Dim oDisp
Dim sUrl As String
'slot protocol causes OOo crash...
if oUrl.Protocol = "slot:" Then
Exit Function
End If
If bDebug Then
Print oUrl.complete
End If
'do your dispatch management here:
Select Case oUrl.complete
Case ".uno:Copy"
oDisp = GetCopyDispatch 'replace the original dispatch
Case ".uno:Paste"
oDisp = GetCopyDispatch 'replace the original dispatch
Case ".uno:Save"
oDisp = GetCopyDispatch 'replace the original dispatch
Case ".uno:Undo"
oDisp = GetCopyDispatch 'replace the original dispatch
case ".uno:CloseWin"
oDisp = GetCopyDispatch 'replace the original dispatch
case "uno:CloseDoc"
oDisp = GetCopyDispatch 'replace the original dispatch
'Case ".uno:blabla"
'do something
Case Else
oDisp = _
oSlaveDispatchProvider.queryDispatch( oUrl, sTargetFrameName, lSearchFlags )
End Select
ThisFrame_queryDispatch = oDisp
End Function
Function ThisFrame_queryDispatches ( mDispatches ) As Variant
'ThisFrame_queryDispatches = mDispatches()
End Function
Function ThisFrame_getSlaveDispatchProvider ( ) As Variant
ThisFrame_getSlaveDispatchProvider = oSlaveDispatchProvider
End Function
Sub ThisFrame_setSlaveDispatchProvider ( oSDP )
oSlaveDispatchProvider = oSDP
End Sub
Function ThisFrame_getMasterDispatchProvider ( ) As Variant
ThisFrame_getMasterDispatchProvider = oMasterDispatchProvider
End Function
Sub ThisFrame_setMasterDispatchProvider ( oMDP )
303
oMasterDispatchProvider = oMDP
End Sub
Sub toggleDebug
bDebug = Not bDebug
End Sub
Function GetCopyDispatch()
If Not IsNull(oCopyDispatch) Then
oCopyDispatch = _
CreateUnoListener("MyCustom_", "com.sun.star.frame.XDispatch")
End If
GetCopyDispatch = oCopyDispatch
End Function
Sub MyCustom_dispatch(URL, Arguments)
Select Case URL.complete
Case ".uno:Copy"
MsgBox "Sorry, the original " & URL.complete & _
" dispatch was stolen from Paolo M.", 48
Case ".uno:Paste"
ThisComponent.CurrentSelection(0).String = _
"**** ARBITRARY CLIPBOARD CONTENT PROVIDED BY PAOLO M. ****"
Case ".uno:Save"
MsgBox "Sorry, the original " & URL.complete & _
" dispatch was stolen from Paolo M.", 48
Case ".uno:Undo"
MsgBox "Undo What????!!!???", 16
case ".uno:CloseWin"
msgbox "CloseWin"
case "uno:CloseDoc"
msgbox "CloseDoc"
Case Else
End Select
End Sub
Sub MyCustom_addStatusListener(Control, URL)
End Sub
Sub MyCustom_removeStatusListener (Control, URL)
end sub
Edit:
(marked as solved as I got to how to do it even though it seems it can't be done in Basic. Thanks for the help.)