Re: Prevent closing with InstanceLocker

2012-12-29 Thread Ariel Constenla-Haile
On Thu, Dec 27, 2012 at 04:50:13PM +0100, Bernard Marcelly wrote:
 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

Useful too a quick search in bugzilla shows:
https://issues.apache.org/ooo/buglist.cgi?quicksearch=InstanceLocker

https://issues.apache.org/ooo/show_bug.cgi?id=118965
https://issues.apache.org/ooo/show_bug.cgi?id=118966
https://issues.apache.org/ooo/show_bug.cgi?id=118896

Looks like this service didn't get enough qa and it's really broken.


Regard
-- 
Ariel Constenla-Haile
La Plata, Argentina


pgpu4xb0cs3Ok.pgp
Description: PGP signature


Re: Prevent closing with InstanceLocker

2012-12-27 Thread Bernard Marcelly

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




Prevent closing with InstanceLocker

2012-12-26 Thread Bernard Marcelly

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.
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.


Does anybody have a working code in Basic ?

Regards
  Bernard