[Solved] XDesktop::Terminate()

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
nloredan
Posts: 9
Joined: Fri Aug 14, 2009 5:56 am

[Solved] XDesktop::Terminate()

Post 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.
Last edited by Hagar Delest on Sun Apr 17, 2011 9:12 pm, edited 1 time in total.
Reason: tagged [Solved].
OpenOffice.org SDK 3.3.0 on Windows 7 x64 / Mac OS X Lion Mountain
User avatar
MrProgrammer
Moderator
Posts: 4905
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA

Re: XDesktop::Terminate()

Post 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.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.6.3, iMac Intel.   The locale for any menus or Calc formulas in my posts is English (USA).
nloredan
Posts: 9
Joined: Fri Aug 14, 2009 5:56 am

Re: XDesktop::Terminate()

Post 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.
OpenOffice.org SDK 3.3.0 on Windows 7 x64 / Mac OS X Lion Mountain
nloredan
Posts: 9
Joined: Fri Aug 14, 2009 5:56 am

Re: XDesktop::Terminate()

Post 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?
OpenOffice.org SDK 3.3.0 on Windows 7 x64 / Mac OS X Lion Mountain
nloredan
Posts: 9
Joined: Fri Aug 14, 2009 5:56 am

Re: XDesktop::Terminate()

Post 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?
OpenOffice.org SDK 3.3.0 on Windows 7 x64 / Mac OS X Lion Mountain
rudolfo
Volunteer
Posts: 1488
Joined: Wed Mar 19, 2008 11:34 am
Location: Germany

Re: XDesktop::Terminate()

Post 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
OpenOffice 3.1.1 (2.4.3 until October 2009) and LibreOffice 3.3.2 on Windows 2000, AOO 3.4.1 on Windows 7
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
nloredan
Posts: 9
Joined: Fri Aug 14, 2009 5:56 am

Re: XDesktop::Terminate()

Post 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.
OpenOffice.org SDK 3.3.0 on Windows 7 x64 / Mac OS X Lion Mountain
rudolfo
Volunteer
Posts: 1488
Joined: Wed Mar 19, 2008 11:34 am
Location: Germany

Re: XDesktop::Terminate()

Post 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.
OpenOffice 3.1.1 (2.4.3 until October 2009) and LibreOffice 3.3.2 on Windows 2000, AOO 3.4.1 on Windows 7
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
nloredan
Posts: 9
Joined: Fri Aug 14, 2009 5:56 am

Re: XDesktop::Terminate()

Post 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.
OpenOffice.org SDK 3.3.0 on Windows 7 x64 / Mac OS X Lion Mountain
B Marcelly
Volunteer
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: XDesktop::Terminate()

Post 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
Bernard

OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
nloredan
Posts: 9
Joined: Fri Aug 14, 2009 5:56 am

Re: XDesktop::Terminate()

Post 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!!!
OpenOffice.org SDK 3.3.0 on Windows 7 x64 / Mac OS X Lion Mountain
Post Reply