[Solved] Cancelling XTopWindowListener windowClosing

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
JeJe
Volunteer
Posts: 2779
Joined: Wed Mar 09, 2016 2:40 pm

[Solved] Cancelling XTopWindowListener windowClosing

Post 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::star::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)
Last edited by floris v on Sun Sep 08, 2019 9:18 am, edited 2 times in total.
Reason: Added Solved icon, floris v, moderator
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
JeJe
Volunteer
Posts: 2779
Joined: Wed Mar 09, 2016 2:40 pm

Re: Cancelling XTopWindowListener windowClosing

Post 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)
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Cancelling XTopWindowListener windowClosing

Post by Villeroy »

This is one of the many things I never figured out in 16 years.
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
User avatar
floris v
Volunteer
Posts: 4430
Joined: Wed Nov 28, 2007 1:21 pm
Location: Netherlands

Re: Cancelling XTopWindowListener windowClosing

Post 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. :?
OpenOffice 4.1.11 on Ubuntu; LibreOffice 6.4 on Linux Mint, LibreOffice 7.6.2.1 on Ubuntu
If your problem has been solved or your question has been answered, please edit the first post in this thread and add [Solved] to the title bar.
Nederlandstalig forum
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Cancelling XTopWindowListener windowClosing

Post 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
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: 2779
Joined: Wed Mar 09, 2016 2:40 pm

Re: Cancelling XTopWindowListener windowClosing

Post 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.)
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
JeJe
Volunteer
Posts: 2779
Joined: Wed Mar 09, 2016 2:40 pm

Re: [Solved] Cancelling XTopWindowListener windowClosing

Post 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
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Post Reply