| Edit: Changed subject, was Closed Not on My Will Make your post understandable by others -- MrProgrammer, forum moderator |
[Dropped] Keep background document open after foreground document is closed
[Dropped] Keep background document open after foreground document is closed
Use OpenOffice to open a document in the background, and then open another document in the foreground. When closing the front-end document, it exits the program and also closes the background document. How can this issue be resolved?
Last edited by MrProgrammer on Tue Aug 01, 2023 6:00 pm, edited 1 time in total.
Reason: Dropped: No response from wanglong after trying AWT window -- MrProgrammer, forum moderator
Reason: Dropped: No response from wanglong after trying AWT window -- MrProgrammer, forum moderator
Libre Office 7.6 on Windows 11.
Re: Closed Not on My Will
Please show the code you are using.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Re: Closed Not on My Will
Code: Select all
public void newDocComponentFromTemplate(boolean Hidden)
throws java.lang.Exception {
java.io.File sourceFile = new java.io.File(filePath);
StringBuffer sTemplateFileUrl = new StringBuffer("file:///");
sTemplateFileUrl.append(sourceFile.getCanonicalPath().replace('\\', '/'));
String loadUrl = sTemplateFileUrl.toString();
mxRemoteServiceManager = this.getRemoteServiceManager();
desktop = mxRemoteServiceManager.createInstanceWithContext(
"com.sun.star.frame.Desktop", mxRemoteContext);
XComponentLoader xComponentLoader = (XComponentLoader)
UnoRuntime.queryInterface(XComponentLoader.class, desktop);
PropertyValue[] loadProps = new PropertyValue[2];
loadProps[0] = new PropertyValue();
loadProps[0].Name = "AsTemplate";
loadProps[0].Value = new Boolean(true);
loadProps[1] = new PropertyValue();
loadProps[1].Name = "Hidden";
loadProps[1].Value = Hidden;
xComp = xComponentLoader.loadComponentFromURL(loadUrl, "_blank",
0, loadProps);
}
Libre Office 7.6 on Windows 11.
Re: Closed Not on My Will
There are dedicated functions for managing the Windows Paths and regular URLs:
ConvertToURL(), and the ConvertFromURL()
https://wiki.openoffice.org/wiki/URL_Basics
ConvertToURL(), and the ConvertFromURL()
https://wiki.openoffice.org/wiki/URL_Basics
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Re: Closed Not on My Will
Okay, I accept your suggestion. But it seems to be of no help to my problem.
Libre Office 7.6 on Windows 11.
Re: Closed Not on My Will
Testing, it seems that closing the last non-hidden window terminates the application. So you'll need to keep something non-hidden open. Another way so a window isn't seen - without being non visible - it to position it offscreen.
Edit:
You can have a listener for the view going to be closed event - using that you might or might not be able to do something in response to the user closing the window to prevent shutdown.
Edit:
You can have a listener for the view going to be closed event - using that you might or might not be able to do something in response to the user closing the window to prevent shutdown.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: Keep hidden document open after closing foreground document
Moving the window off-screen is a good suggestion, but through experimentation, it has been found that it is not possible to move the window out of the screen by changing its position. OpenOffice ensures that the entire window remains within the visible area of the screen.
[10000,10000] has no actual effects.
[-1,-1] will also leave a title bar window.
Code: Select all
xFrame.getContainerWindow().setPosSize(10000,10000,-1,-1, PosSize.POSSIZE);
[-1,-1] will also leave a title bar window.
Libre Office 7.6 on Windows 11.
Re: Keep hidden document open after closing foreground document
You can use the Windows API. Hides off screen and makes so cannot be activated:
There's also ShowWindow to look at. The window will still be in the Windows Taskbar - if that's unwanted there'll likely be a way to remove it with the Windows API too.
Code: Select all
Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Const SWP_NOMOVE = &H2
Const SWP_NOACTIVATE = &H10
Const SWP_SHOWWINDOW = &H40
Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) as Long
' '
Declare Sub SetWindowPos Lib "User32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)
Sub MoveComponentWindowOffScreen
hwnd = thiscomponent.currentcontroller.frame.containerwindow.getwindowhandle(array(),1)
movewindow hwnd, -400,-400,100,100,false
SetWindowPos hWnd, HWND_NOTOPMOST, -300, -300, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
End Sub
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: Keep hidden document open after closing foreground document
Pared down, and better named sub:
Code: Select all
Const SWP_NOACTIVATE = &H10
Const SWP_SHOWWINDOW = &H40
Declare Sub SetWindowPos Lib "User32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)
Sub MoveThisComponentWindowOffScreen
hwnd = thiscomponent.currentcontroller.frame.containerwindow.getwindowhandle(array(),1)
SetWindowPos hWnd, HWND_NOTOPMOST, -300, -300, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW
End Sub
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: Keep hidden document open after closing foreground document
Thank you very much for your suggestion, JeJe. However, as far as I know, OpenOffice does not support direct execution of VBA scripts, and I don't want to use Windows API either because I need to ensure that my plugin is cross-platform compatible.
Libre Office 7.6 on Windows 11.
Re: Keep hidden document open after closing foreground document
The code isn't VBA - you can declare Windows API functions at the top of a module in OOBasic anyway. So long as they don't require things like pointers, they'll work. Not cross-platform though unfortunately.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: Keep hidden document open after closing foreground document
You might be able to use a ToWindowListener so that whenever its activated its kept minimized.
https://www.openoffice.org/api/docs/com ... tener.html
https://www.openoffice.org/api/docs/com ... tener.html
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: Keep hidden document open after closing foreground document
You could also try creating another window such as an AWT window without a titlebar - which you might be able to resize to near zero size - and see whether that keeps the application open.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: Keep hidden document open after closing foreground document
Moving the window offscreen and keeping it minimized is a viable solution, but as a customer, I would feel that having an uncloseable OpenOffice instance in the taskbar is not a good user experience. Additionally, I believe that closing the front document should not result in the termination of the entire OpenOffice process; it seems like a bug within OpenOffice itself. Is there a way to address this issue by modifying the code within OpenOffice?
Libre Office 7.6 on Windows 11.
Re: Keep hidden document open after closing foreground document
Creating a document with no title bar and size [0,0] has been attempted as a solution, but all solutions inevitably result in an OpenOffice process icon remaining open in the taskbar, which is not a good customer experience.
Libre Office 7.6 on Windows 11.
Re: Keep hidden document open after closing foreground document
Sure... the sourcecode is there for you to modify as you wish... but that's program development and you'll need to look elsewhere for help with doing that.
An AWT window without a titlebar won't show in the taskbar - I don't know whether it will keep the application open though, you'll have to test for that.
https://wiki.openoffice.org/wiki/Playin ... oolkit_AWT
An AWT window without a titlebar won't show in the taskbar - I don't know whether it will keep the application open though, you'll have to test for that.
https://wiki.openoffice.org/wiki/Playin ... oolkit_AWT
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: Keep hidden document open after closing foreground document
Thank you very much,JeJe!
I will try the AWT window method and give a reply.
I will try the AWT window method and give a reply.
Libre Office 7.6 on Windows 11.
Re: Keep hidden document open after closing foreground document
Shouldn't it be a good idea to tell us for what reasons the questioner thinks such functionality is useful or for what it is supposed to be needed?
On Windows 10: LibreOffice 25.2.4 and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
---
Lupp from München
Re: Keep hidden document open after closing foreground document
Sure, now I can assume a scenario. When we want to use an ODT document (called the library document) as a base library to generate other ODT documents (called instance documents), we may encounter the following situation: the library document is opened in the background for multiple processing of other documents, because the library document may be very large and will be reused multiple times after initial parsing.
Libre Office 7.6 on Windows 11.
Re: Keep hidden document open after closing foreground document
You "can assume" and "may encounter". This doesn't sound very realistic. Where is a real use-case?
Anyway you need a grip on the hidden document to be able to make any use of it. There must be an accessible instance having that grip. And since you can't run code from a different document but the calling one, every document you may want to be manipulated by code from that library would need to be a child of the library document therefore, wouldn't it?
The appropriate means to provide a library isn't a hidden document, but a loadable Library stored to the user profile.
I wouldn't change that. A way to use distributable documents to spread a library, probably without telling afflicted user about the fact would cause security issues.
...
See also: https://ask.libreoffice.org/t/create-a- ... ed/93843/6 where this thread is linked to.
Anyway you need a grip on the hidden document to be able to make any use of it. There must be an accessible instance having that grip. And since you can't run code from a different document but the calling one, every document you may want to be manipulated by code from that library would need to be a child of the library document therefore, wouldn't it?
The appropriate means to provide a library isn't a hidden document, but a loadable Library stored to the user profile.
I wouldn't change that. A way to use distributable documents to spread a library, probably without telling afflicted user about the fact would cause security issues.
...
See also: https://ask.libreoffice.org/t/create-a- ... ed/93843/6 where this thread is linked to.
On Windows 10: LibreOffice 25.2.4 and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
---
Lupp from München