Page 1 of 1

[Solved] XDesktop::Terminate()

Posted: Sun Apr 10, 2011 5:08 pm
by nloredan
My application is written in C++ and implements the XTerminateListener interface as explained below:
http://wiki.services.openoffice.org/wik ... he_Desktop
Writer (or any other OpenOffice.org application) closes when I call XDesktop::Terminate from my application. Is that normal?
I'm using OpenOffice.org SDK 3.2.1.

Re: XDesktop::Terminate()

Posted: Mon Apr 11, 2011 6:12 am
by MrProgrammer
The [color=#0080FF]Using_the_Desktop[/color] link you posted wrote:The office process is usually terminated when the user selects File - Exit ….
Clients can terminate the office through a call to terminate() ….
Here "The office" means Writer, Calc, etc.
nloredan wrote:Writer (or any other OpenOffice.org application) closes when I call XDesktop::Terminate from my application. Is that normal?
Seems to me that it's doing what you asked it to do.

Re: XDesktop::Terminate()

Posted: Mon Apr 11, 2011 6:27 am
by nloredan
Thank you for getting back to me so quickly.
Then my next question is: how can I make sure soffice.bin and soffice.exe are properly closed when I quit my application?
The Quickstarter is off and does not launch at startup.
Thanks in advance.

Re: XDesktop::Terminate()

Posted: Wed Apr 13, 2011 7:32 am
by nloredan
I now realize my previous question is not clear enough. I know how to terminate soffice. I just need to know why XDesktop::Terminate does not return FALSE when I close my application while Writer is still open. Instead, it returns TRUE and Writer is closed. How to avoid that?

Re: XDesktop::Terminate()

Posted: Wed Apr 13, 2011 7:33 am
by nloredan
I now realize my previous question is not clear enough. I know how to terminate soffice. I just need to know why XDesktop::Terminate does not return FALSE when I close my application while Writer is still open. Instead, it returns TRUE and Writer is closed. How to avoid that?

Re: XDesktop::Terminate()

Posted: Wed Apr 13, 2011 10:21 am
by rudolfo
nloredan wrote:I just need to know why XDesktop::Terminate does not return FALSE when I close my application while Writer is still open. Instead, it returns TRUE and Writer is closed.
Terminate() is a method it processes something, it is not an attribute of that you can check the state. The API Docs for XDesktop::terminate() say:
API wrote:Description tries to terminate the desktop.

First, every terminate listener is called by his XTerminateListener::queryTermination() method. Throwing of a TerminationVetoException can break the termination process and the listener how has done that will be the new "controller" of the desktop lifetime. He should try to terminate it by himself after his own processes will be finished. If nobody disagree with the termination request, every listener will be called by his XTerminateListener::notifyTermination() method.
Returns
true - if all listener agree with this request
false - otherwise

Re: XDesktop::Terminate()

Posted: Thu Apr 14, 2011 3:58 am
by nloredan
Thank you for your answer. However, I think you've missed to answer my questions:
1. why Writer does not throw a TerminationVetoException when I call XDesktop::terminate() from my application?
2. if XDesktop::terminate() is not the right way to do what I want, what other interface (method) should I implement (call)?
I simply want to terminate soffice when I quit my application, unless other application is running (i.e. Writer) - in which case, Writer's state should not be affected.

Re: XDesktop::Terminate()

Posted: Thu Apr 14, 2011 4:26 pm
by rudolfo
Sorry, your previous posts did not make clear, that you are well aware what should happen when calling XDesktop::terminate() and that you assume a bug or a miss-configuration in the behaviour of OpenOffice that you can observe.
One explanation for the behaviour would be that writer activates the termination listener only when the document is modified. You should be able to test this manually when you open two documents and close the OOo application.

I am a bit irritated, how you could get into a situation where you close an document or window that you did not open. If you attach to an Office process in the beginning the logical symmetrical action is to de-attach and not to terminate.

Re: XDesktop::Terminate()

Posted: Sat Apr 16, 2011 7:46 am
by nloredan
Thank you very much for your answer. It explains a lot to me.
I must say I don't attach my application to a OOo process. The scenario is described below:
1. soffice.exe is not running
2. I start my application which starts the soffice.exe process
3. I then start Writer
4. When I quit my application I call XDesktop::terminate() which closes soffice and Writer.
I don't know yet if that is a bug in my code or OOo. This is what I'm trying to find out.
Thanks in advance.

Re: XDesktop::Terminate()

Posted: Sat Apr 16, 2011 8:17 am
by B Marcelly
Hi,
nloredan wrote: I simply want to terminate soffice when I quit my application, unless other application is running (i.e. Writer) - in which case, Writer's state should not be affected.
Once you have closed your document, enumerate the components of the Desktop. If there is none, terminate soffice.
Desktop > getComponents() > createEnumeration() > hasMoreElements() > True/False

Re: XDesktop::Terminate()

Posted: Sun Apr 17, 2011 7:16 pm
by nloredan
B Marcelly wrote:Once you have closed your document, enumerate the components of the Desktop. If there is none, terminate soffice.
Desktop > getComponents() > createEnumeration() > hasMoreElements() > True/False
That's exactly what I needed to know! Thank you so much for your help.
You're awesome!!!