2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 import com
.sun
.star
.frame
.XDesktop
;
20 import com
.sun
.star
.lang
.XMultiServiceFactory
;
21 import com
.sun
.star
.uno
.UnoRuntime
;
22 import com
.sun
.star
.uno
.XInterface
;
23 import com
.sun
.star
.accessibility
.XAccessible
;
24 import com
.sun
.star
.awt
.XExtendedToolkit
;
27 /** This class tries to simplify some tasks like loading a document or
28 getting various objects.
30 public class SimpleOffice
32 private XDesktop mxDesktop
= null;
33 private OfficeConnection aConnection
;
34 private int mnPortNumber
;
36 public SimpleOffice (int nPortNumber
)
38 mnPortNumber
= nPortNumber
;
43 public void connect ()
45 aConnection
= new OfficeConnection (mnPortNumber
);
60 public XDesktop
getDesktop ()
62 if (mxDesktop
!= null)
66 // Get the factory of the connected office.
67 XMultiServiceFactory xMSF
= aConnection
.getServiceManager ();
70 MessageArea
.println ("can't connect to office");
74 MessageArea
.println ("Connected successfully.");
76 // Create a new desktop.
77 mxDesktop
= UnoRuntime
.queryInterface(
79 xMSF
.createInstance ("com.sun.star.frame.Desktop")
84 MessageArea
.println ("caught exception while creating desktop: "
92 /** Return a reference to the extended toolkit which is a broadcaster of
93 top window, key, and focus events.
95 public XExtendedToolkit
getExtendedToolkit ()
97 XExtendedToolkit xToolkit
= null;
100 // Get the factory of the connected office.
101 XMultiServiceFactory xMSF
= aConnection
.getServiceManager ();
104 xToolkit
= UnoRuntime
.queryInterface(
105 XExtendedToolkit
.class,
106 xMSF
.createInstance ("stardiv.Toolkit.VCLXToolkit")
112 MessageArea
.println ("caught exception while creating extended toolkit: " + e
);
120 public XAccessible
getAccessibleObject (XInterface xObject
)
122 XAccessible xAccessible
= null;
125 xAccessible
= UnoRuntime
.queryInterface(
126 XAccessible
.class, xObject
);
130 MessageArea
.println (
131 "caught exception while getting accessible object" + e
);