Conforming the explained here: https://wiki.openoffice.org/wiki/Docume ... /Documents
i had an unexpected result working with several form windows and frames at same time.
That doc in the said url is saying that 'thisComponent' is the correct way to obtain the current document location and not 'StarDesktop.CurrentComponent'.
But detecting resolution of all the opened windows 'thisComponent' kept referring to the first opened window form, instead of the active window.
It was very strange for me because that doc in the said url is very EXPLICIT, and curiously i obtained the correct result using 'StarDesktop.CurrentComponent' and not the famous 'thisComponent'.
think about ?
Unexpected ThisComponent fail
Unexpected ThisComponent fail
OpenOffice last version | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
Re: Unexpected ThisComponent fail
thisComponent returns the current document from which the macro is run. You need to cycle through the open components using some other UNO construct
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
Re: Unexpected ThisComponent fail
Until today I do not get the difference between a model and a component. In my understanding, both mean "document".
ThisComponent is the embedding document of a macro (except Base, sigh).
ThisDatabaseDocument is the embedding database document of a macro.
ThisComponent is the active document (including Base document) if the code is in runnin in global scope ("My Macros" or "XOffice Macros")
ThisComponent in global scope includes help documents which gives unexpected results when you try to get ThisComponent.getSheets() while the last active window was a help window.
ThisComponent does not include the Basic IDE which makes it possible to run code from the IDE. ThisComponent.getSheets() is possible while the IDE is active and the previously active document was a spreadsheet.
StarDesktop.CurrentController.getModel()
or
StarDesktop.getCurrentModel() is the same as ThisComponent in global scope but this one includes the Basic IDE so you have to call the macro while the intended document is the active one.
StarDesktop.getFrames() may be useful. Every frame has one controller (not so sure; are there any frames without controller?) and the controller may have a model or not. For instance, an MRI frame or the frame of the start screen has a controller to interact with but it has no model.
You can loop through all frames, and test if its controller has a model and then the ImplementationName of the model.
A Writer document with no URL could be a new document or an embedded form. I think you have to add some distinctive property. I would add a unique identifier in the form's document properties (menu:File>Properties... Title, Subject, Keywords or something user defined).
ThisComponent is the embedding document of a macro (except Base, sigh).
ThisDatabaseDocument is the embedding database document of a macro.
ThisComponent is the active document (including Base document) if the code is in runnin in global scope ("My Macros" or "XOffice Macros")
ThisComponent in global scope includes help documents which gives unexpected results when you try to get ThisComponent.getSheets() while the last active window was a help window.
ThisComponent does not include the Basic IDE which makes it possible to run code from the IDE. ThisComponent.getSheets() is possible while the IDE is active and the previously active document was a spreadsheet.
StarDesktop.CurrentController.getModel()
or
StarDesktop.getCurrentModel() is the same as ThisComponent in global scope but this one includes the Basic IDE so you have to call the macro while the intended document is the active one.
StarDesktop.getFrames() may be useful. Every frame has one controller (not so sure; are there any frames without controller?) and the controller may have a model or not. For instance, an MRI frame or the frame of the start screen has a controller to interact with but it has no model.
You can loop through all frames, and test if its controller has a model and then the ImplementationName of the model.
A Writer document with no URL could be a new document or an embedded form. I think you have to add some distinctive property. I would add a unique identifier in the form's document properties (menu:File>Properties... Title, Subject, Keywords or something user defined).
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice