Does the InstanceLocker work if you provide an XActionsApproval (in
Basic, via a UNO listener)? In a dummy test, AOO crashed.

Indeed, it works for me if there is another OpenOffice window in the background. But running my routine allowClose still closes the window.

If the document is the unique window, the closing attempt still freezes 
OpenOffice.
Here is my new code.

Option Explicit

Global dontClose As Object, closeDenier As Object

Sub denyClose
if IsNull(dontClose)  then
  closeDenier = CreateUnoListener("nono_", 
"com.sun.star.embed.XActionsApproval")
dontClose = com.sun.star.embed.InstanceLocker.InstanceLockerCtor2(StarDesktop.CurrentFrame, com.sun.star.embed.Actions.PREVENT_CLOSE, closeDenier)
end if
End Sub


Sub allowClose
if not IsNull(dontClose)  then
  dontClose.dispose
  closeDenier = Nothing
  dontClose = Nothing
end if
End Sub


function nono_approveAction(nAction As Long) As Boolean
nono_approveAction = True
end function


Another thing that does not work is that disposing the InstanceLocker
that is vetoing the closing of the frame, the frame gets closed even if
I don't close it manually. I understood the specification as saying that
disposing the InstanceLocker will remove the close listener, not close
the instance. How do you interpret this?


"After creation the service adds a listener of requested type ( close, terminate and/or etc. ) to the controlled object and let the listener throw related veto exception until the service is disposed."

I have the same interpretation. After disposal of the service the programmer should be free to let the window (or the document) open or close it.

Useful references from old mailing lists:
  Annoucement of service InstanceLocker (May 2006)
<http://www.mail-archive.com/allfeatures@openoffice.org/msg00282.html>
  Problem with InstanceLocker in Basic (Oct 2007)
<http://www.mail-archive.com/dev@api.openoffice.org/msg06210.html>

Regards
  Bernard


Reply via email to