Hi Marcel,

On Thu, Dec 27, 2012 at 08:55:59AM +0100, Bernard Marcelly wrote:
> Hello,
> 
> With OpenOffice Basic, I want to prevent a document from closing.
> I tried this simple code, stored in a Writer document:
> 
> Option Explicit
> 
> Global dontClose As Object
> 
> Sub denyClose
> if IsNull(dontClose)  then
>   dontClose =
> com.sun.star.embed.InstanceLocker.InstanceLockerCtor1(ThisComponent,
> com.sun.star.embed.Actions.PREVENT_CLOSE)
> end if
> End Sub
> 
> Sub allowClose
> if not IsNull(dontClose)  then
>   dontClose.dispose
>   dontClose = Nothing
> end if
> End Sub
> 
> 
> The code was tested on AOO 3.4.1 with Windows XP Home.
> 1 - I run macro denyClose. I still can close the document.

There is a bug in the implementation: http://s.apache.org/FC9 circa line
353 a CloseVetoException is only thrown *only* when there is an
XActionsApproval instance and it approves preventing close.

This is obviously wrong, as it makes useless the first constructor (the
one without an XActionsApproval instance). Also, the second constructor
is said to admit an empty reference for the XActionsApproval, in which
case it should behave like the first constructor.

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

> 2 - I load the document again, I run macro denyClose. Then I run
> macro allowClose : the document closes.
> 
> I changed the argument ThisComponent to : StarDesktop.CurrentFrame
> 
> I run macro denyClose. I can't close the document. But OpenOffice
> freezes and I have to kill it.

I can reproduce it when there is only one frame in the desktop, the one
with the document that is running the macro. There seems to be a dead
lock, according to the backtrace.

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?


Regards
-- 
Ariel Constenla-Haile
La Plata, Argentina

Attachment: pgp24ihrWppN9.pgp
Description: PGP signature

Reply via email to