Singletons and the Automation bridge

82 views Asked by At

The type com.sun.star.frame.Desktop is deprecated, and it is recommended to use the com.sun.star.frame.theDesktop singleton instead.

Other language bindings support access to a singleton. In Java, this thread says the following works:

com.sun.star.frame.theDesktop.get(componentContext)

However, the com.sun.star.frame namespace isn't available under the Automation bridge; there is only the single entry point of the service manager:

var objServiceManager = new ActiveXObject('com.sun.star.ServiceManager');

How can I acces this (and other) singletons?

(Originally posted on ask.libreoffice)

1

There are 1 answers

0
Zev Spitz On BEST ANSWER

Singletons are accessed using the getByName method on the script context, passing in a string path to the singleton:

'/singletons/com.sun.star.frame.theDesktop'

The Automation bridge exposes the script context at the DefaultContext property on the service manager:

var serviceManager = new ActiveXObject('com.sun.star.ServiceManager');
var desktop = serviceManager.defaultContext.getByName('/singletons/com.sun.star.frame.theDesktop');

(I was led to the solution by this post where the author is trying to automate OpenOffice using Delphi.)