Page 1 of 1
					
				[Solved] Cancelling XTopWindowListener windowClosing
				Posted: Fri Sep 06, 2019 5:32 pm
				by JeJe
				I'm wrting an extension where I'd like a menu to pop up with more options when a document's close button is pressed. I can do this using the XTopWindowListener windowClosing event. 
I'd like one of the options to be to cancel/override the close. The documentation says this can be done - but the event is one way and nowhere can I find how. Anyone know?
https://www.openoffice.org/api/docs/com ... dowClosing
windowClosing
[oneway] void
windowClosing([in] ::com::sun:

:lang::EventObject
Description
    is invoked when a window is in the process of being closed. 
    The close operation can be overridden at this point.
Edit: 
(I've done the search for all the XTopWindowListener threads here and with a search engine without finding anything)
 
			 
			
					
				Re: Cancelling XTopWindowListener windowClosing
				Posted: Sat Sep 07, 2019 10:58 am
				by JeJe
				I've tried using suspend on the controller but that doesn't do it.
https://www.openoffice.org/api/docs/com ... ml#suspend
(Edit: its not all that important for what I'm trying to do BTW, I can do without, its just for completeness)
 
			 
			
					
				Re: Cancelling XTopWindowListener windowClosing
				Posted: Sat Sep 07, 2019 11:38 am
				by Villeroy
				This is one of the many things I never figured out in 16 years.
			 
			
					
				Re: Cancelling XTopWindowListener windowClosing
				Posted: Sat Sep 07, 2019 8:44 pm
				by floris v
				I feel that the Java jargon here is very confusing, but maybe the idea is really much like in good old Delphi. If a user 'd click on the Close icon, a closerequest event would be generated, calling the onCloseRequest method, with the event as single parameter. In that method you'd typically throw a dialog box at the user to ask for confirmation, and only when the user confirms would you call the close method, which would probably first throw a close event.
Don't know if this helps.  

 
			 
			
					
				Re: Cancelling XTopWindowListener windowClosing
				Posted: Sat Sep 07, 2019 9:18 pm
				by Villeroy
				On print page 618 (PDF page 615) of 
https://wiki.openoffice.org/w/images/d/ ... o3.1.0.pdf I found an example how a Java class throws an exception in order to veto an event.
That event is the termination of a frame and the exception is 
https://www.openoffice.org/api/docs/com ... ption.html 
			 
			
					
				Re: Cancelling XTopWindowListener windowClosing
				Posted: Sun Sep 08, 2019 8:17 am
				by JeJe
				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.)
 
			 
			
					
				Re: [Solved] Cancelling XTopWindowListener windowClosing
				Posted: Sun Sep 08, 2019 10:45 am
				by JeJe
				A workaround is a dispatch call to .uno:NewWindow in the XTopWindowListener windowClosing event - and then positioning it at the place where the frame that is about to be closed is. Some other characteristics of that frame may need to be duplicated too.
Edit:may not be very stable