1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ef39d40dSAndrew Rist  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ef39d40dSAndrew Rist  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19*ef39d40dSAndrew Rist  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir package util;
24cdf0e10cSrcweir 
25cdf0e10cSrcweir import com.sun.star.awt.Rectangle;
26cdf0e10cSrcweir import com.sun.star.awt.WindowDescriptor;
27cdf0e10cSrcweir import com.sun.star.awt.XToolkit;
28cdf0e10cSrcweir import com.sun.star.awt.XWindowPeer;
29cdf0e10cSrcweir import com.sun.star.awt.XTopWindow;
30cdf0e10cSrcweir import com.sun.star.beans.PropertyValue;
31cdf0e10cSrcweir import com.sun.star.beans.XPropertySet;
32cdf0e10cSrcweir import com.sun.star.container.XEnumeration;
33cdf0e10cSrcweir import com.sun.star.container.XNameReplace;
34cdf0e10cSrcweir import com.sun.star.frame.XComponentLoader;
35cdf0e10cSrcweir import com.sun.star.frame.XDesktop;
36cdf0e10cSrcweir import com.sun.star.frame.XFrame;
37cdf0e10cSrcweir import com.sun.star.frame.XModel;
38cdf0e10cSrcweir import com.sun.star.lang.XComponent;
39cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
40cdf0e10cSrcweir import com.sun.star.lang.XServiceInfo;
41cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir // access the implementations via names
44cdf0e10cSrcweir import com.sun.star.uno.XInterface;
45cdf0e10cSrcweir import com.sun.star.util.XCloseable;
46cdf0e10cSrcweir import com.sun.star.util.XModifiable;
47cdf0e10cSrcweir import com.sun.star.view.XViewSettingsSupplier;
48cdf0e10cSrcweir import helper.ConfigHelper;
49cdf0e10cSrcweir import java.util.Vector;
50cdf0e10cSrcweir import lib.StatusException;
51cdf0e10cSrcweir 
52cdf0e10cSrcweir /**
53cdf0e10cSrcweir  * contains helper methods for the Desktop
54cdf0e10cSrcweir  */
55cdf0e10cSrcweir public class DesktopTools
56cdf0e10cSrcweir {
57cdf0e10cSrcweir 
58cdf0e10cSrcweir     /**
59cdf0e10cSrcweir      * Queries the XComponentLoader
60cdf0e10cSrcweir      *
61cdf0e10cSrcweir      * @param xMSF the MultiServiceFactory
62cdf0e10cSrcweir      * @return the gained XComponentLoader
63cdf0e10cSrcweir      */
getCLoader(XMultiServiceFactory xMSF)64cdf0e10cSrcweir     public static XComponentLoader getCLoader(XMultiServiceFactory xMSF)
65cdf0e10cSrcweir     {
66cdf0e10cSrcweir         XDesktop oDesktop = (XDesktop) UnoRuntime.queryInterface(
67cdf0e10cSrcweir                 XDesktop.class, createDesktop(xMSF));
68cdf0e10cSrcweir 
69cdf0e10cSrcweir         XComponentLoader oCLoader = (XComponentLoader) UnoRuntime.queryInterface(
70cdf0e10cSrcweir                 XComponentLoader.class, oDesktop);
71cdf0e10cSrcweir 
72cdf0e10cSrcweir         return oCLoader;
73cdf0e10cSrcweir     } // finish getCLoader
74cdf0e10cSrcweir 
75cdf0e10cSrcweir     /**
76cdf0e10cSrcweir      * Creates an Instance of the Desktop service
77cdf0e10cSrcweir      *
78cdf0e10cSrcweir      * @param xMSF the MultiServiceFactory
79cdf0e10cSrcweir      * @return the gained Object
80cdf0e10cSrcweir      */
createDesktop(XMultiServiceFactory xMSF)81cdf0e10cSrcweir     public static Object createDesktop(XMultiServiceFactory xMSF)
82cdf0e10cSrcweir     {
83cdf0e10cSrcweir         Object oInterface;
84cdf0e10cSrcweir 
85cdf0e10cSrcweir         try
86cdf0e10cSrcweir         {
87cdf0e10cSrcweir             oInterface = xMSF.createInstance("com.sun.star.comp.framework.Desktop");
88cdf0e10cSrcweir         }
89cdf0e10cSrcweir         catch (com.sun.star.uno.Exception e)
90cdf0e10cSrcweir         {
91cdf0e10cSrcweir             throw new IllegalArgumentException("Desktop Service not available");
92cdf0e10cSrcweir         }
93cdf0e10cSrcweir 
94cdf0e10cSrcweir         return oInterface;
95cdf0e10cSrcweir     } //finish createDesktop
96cdf0e10cSrcweir 
97cdf0e10cSrcweir     /**
98cdf0e10cSrcweir      * returns a XEnumeration containing all components containing on the desktop
99cdf0e10cSrcweir      * @param xMSF the XMultiServiceFactory
100cdf0e10cSrcweir      * @return XEnumeration of all components on the desktop
101cdf0e10cSrcweir      */
getAllComponents(XMultiServiceFactory xMSF)102cdf0e10cSrcweir     public static XEnumeration getAllComponents(XMultiServiceFactory xMSF)
103cdf0e10cSrcweir     {
104cdf0e10cSrcweir         XDesktop xDesktop = (XDesktop) UnoRuntime.queryInterface(
105cdf0e10cSrcweir                 XDesktop.class, createDesktop(xMSF));
106cdf0e10cSrcweir         return xDesktop.getComponents().createEnumeration();
107cdf0e10cSrcweir     }
108cdf0e10cSrcweir 
109cdf0e10cSrcweir     /**
110cdf0e10cSrcweir      * returns the current component on the desktop
111cdf0e10cSrcweir      * @param xMSF the XMultiServiceFactory
112cdf0e10cSrcweir      * @return XComponent of the current component on the desktop
113cdf0e10cSrcweir      */
getCurrentComponent(XMultiServiceFactory xMSF)114cdf0e10cSrcweir     public static XComponent getCurrentComponent(XMultiServiceFactory xMSF)
115cdf0e10cSrcweir     {
116cdf0e10cSrcweir         XDesktop xDesktop = (XDesktop) UnoRuntime.queryInterface(
117cdf0e10cSrcweir                 XDesktop.class, createDesktop(xMSF));
118cdf0e10cSrcweir         return xDesktop.getCurrentComponent();
119cdf0e10cSrcweir     }
120cdf0e10cSrcweir 
121cdf0e10cSrcweir     /**
122cdf0e10cSrcweir      * returns the current component on the desktop
123cdf0e10cSrcweir      * @param xMSF the XMultiServiceFactory
124cdf0e10cSrcweir      * @return XComponent of the current component on the desktop
125cdf0e10cSrcweir      */
getCurrentFrame(XMultiServiceFactory xMSF)126cdf0e10cSrcweir     public static XFrame getCurrentFrame(XMultiServiceFactory xMSF)
127cdf0e10cSrcweir     {
128cdf0e10cSrcweir         XDesktop xDesktop = (XDesktop) UnoRuntime.queryInterface(
129cdf0e10cSrcweir                 XDesktop.class, createDesktop(xMSF));
130cdf0e10cSrcweir         return xDesktop.getCurrentFrame();
131cdf0e10cSrcweir     }
132cdf0e10cSrcweir 
133cdf0e10cSrcweir     /**
134cdf0e10cSrcweir      * returns an object arrary of all open documents
135cdf0e10cSrcweir      * @param xMSF the MultiServiceFactory
136cdf0e10cSrcweir      * @return returns an Array of document kinds like ["swriter"]
137cdf0e10cSrcweir      */
138cdf0e10cSrcweir     /**
139cdf0e10cSrcweir      * returns an array of all open documents
140cdf0e10cSrcweir      * @param xMSF the XMultiSerivceFactory
141cdf0e10cSrcweir      * @return returns an array of all open documents
142cdf0e10cSrcweir      */
getAllOpenDocuments(XMultiServiceFactory xMSF)143cdf0e10cSrcweir     public static Object[] getAllOpenDocuments(XMultiServiceFactory xMSF)
144cdf0e10cSrcweir     {
145cdf0e10cSrcweir         Vector components = new Vector();
146cdf0e10cSrcweir         XDesktop xDesktop = (XDesktop) UnoRuntime.queryInterface(
147cdf0e10cSrcweir                 XDesktop.class, createDesktop(xMSF));
148cdf0e10cSrcweir 
149cdf0e10cSrcweir         XEnumeration allComp = getAllComponents(xMSF);
150cdf0e10cSrcweir 
151cdf0e10cSrcweir         while (allComp.hasMoreElements())
152cdf0e10cSrcweir         {
153cdf0e10cSrcweir             try
154cdf0e10cSrcweir             {
155cdf0e10cSrcweir                 XComponent xComponent = (XComponent) UnoRuntime.queryInterface(
156cdf0e10cSrcweir                         XComponent.class, allComp.nextElement());
157cdf0e10cSrcweir 
158cdf0e10cSrcweir                 if (getDocumentType(xComponent) != null)
159cdf0e10cSrcweir                 {
160cdf0e10cSrcweir                     components.add(xComponent);
161cdf0e10cSrcweir                 }
162cdf0e10cSrcweir 
163cdf0e10cSrcweir             }
164cdf0e10cSrcweir             catch (com.sun.star.container.NoSuchElementException e)
165cdf0e10cSrcweir             {
166cdf0e10cSrcweir             }
167cdf0e10cSrcweir             catch (com.sun.star.lang.WrappedTargetException e)
168cdf0e10cSrcweir             {
169cdf0e10cSrcweir             }
170cdf0e10cSrcweir         }
171cdf0e10cSrcweir         return components.toArray();
172cdf0e10cSrcweir     }
173cdf0e10cSrcweir 
174cdf0e10cSrcweir     /**
175cdf0e10cSrcweir      * Returns the document type for the given XComponent of an document
176cdf0e10cSrcweir      * @param xComponent the document to query for its type
177cdf0e10cSrcweir      * @return possible:
178cdf0e10cSrcweir      * <ul>
179cdf0e10cSrcweir      * <li>swriter</li>
180cdf0e10cSrcweir      * <li>scalc</li>
181cdf0e10cSrcweir      * <li>sdraw</li>
182cdf0e10cSrcweir      * <li>smath</li>
183cdf0e10cSrcweir      * </ul>
184cdf0e10cSrcweir      * or <CODE>null</CODE>
185cdf0e10cSrcweir      */
getDocumentType(XComponent xComponent)186cdf0e10cSrcweir     public static String getDocumentType(XComponent xComponent)
187cdf0e10cSrcweir     {
188cdf0e10cSrcweir         XServiceInfo sInfo = (XServiceInfo) UnoRuntime.queryInterface(
189cdf0e10cSrcweir                 XServiceInfo.class, xComponent);
190cdf0e10cSrcweir 
191cdf0e10cSrcweir         if (sInfo == null)
192cdf0e10cSrcweir         {
193cdf0e10cSrcweir             return "";
194cdf0e10cSrcweir         }
195cdf0e10cSrcweir         else if (sInfo.supportsService("com.sun.star.sheet.SpreadsheetDocument"))
196cdf0e10cSrcweir         {
197cdf0e10cSrcweir             return "scalc";
198cdf0e10cSrcweir         }
199cdf0e10cSrcweir         else if (sInfo.supportsService("com.sun.star.text.TextDocument"))
200cdf0e10cSrcweir         {
201cdf0e10cSrcweir             return "swriter";
202cdf0e10cSrcweir         }
203cdf0e10cSrcweir         else if (sInfo.supportsService("com.sun.star.drawing.DrawingDocument"))
204cdf0e10cSrcweir         {
205cdf0e10cSrcweir             return "sdraw";
206cdf0e10cSrcweir         }
207cdf0e10cSrcweir         else if (sInfo.supportsService("com.sun.star.presentation.PresentationDocument"))
208cdf0e10cSrcweir         {
209cdf0e10cSrcweir             return "simpress";
210cdf0e10cSrcweir         }
211cdf0e10cSrcweir         else if (sInfo.supportsService("com.sun.star.formula.FormulaProperties"))
212cdf0e10cSrcweir         {
213cdf0e10cSrcweir             return "smath";
214cdf0e10cSrcweir         }
215cdf0e10cSrcweir         else
216cdf0e10cSrcweir         {
217cdf0e10cSrcweir             return null;
218cdf0e10cSrcweir         }
219cdf0e10cSrcweir     }
220cdf0e10cSrcweir 
221cdf0e10cSrcweir     /**
222cdf0e10cSrcweir      * Opens a new document of a given kind
223cdf0e10cSrcweir      * with arguments
224cdf0e10cSrcweir      * @return the XComponent Interface of the document
225cdf0e10cSrcweir      * @param kind the kind of document to load.<br>
226cdf0e10cSrcweir      * possible:
227cdf0e10cSrcweir      * <ul>
228cdf0e10cSrcweir      * <li>swriter</li>
229cdf0e10cSrcweir      * <li>scalc</li>
230cdf0e10cSrcweir      * <li>sdaw</li>
231cdf0e10cSrcweir      * <li>smath</li>
232cdf0e10cSrcweir      * </ul>
233cdf0e10cSrcweir      * @param Args arguments which passed to the document to load
234cdf0e10cSrcweir      * @param xMSF the MultiServiceFactory
235cdf0e10cSrcweir      */
openNewDoc(XMultiServiceFactory xMSF, String kind, PropertyValue[] Args)236cdf0e10cSrcweir     public static XComponent openNewDoc(XMultiServiceFactory xMSF, String kind,
237cdf0e10cSrcweir             PropertyValue[] Args)
238cdf0e10cSrcweir     {
239cdf0e10cSrcweir         XComponent oDoc = null;
240cdf0e10cSrcweir 
241cdf0e10cSrcweir         try
242cdf0e10cSrcweir         {
243cdf0e10cSrcweir             oDoc = getCLoader(xMSF).loadComponentFromURL("private:factory/" + kind,
244cdf0e10cSrcweir                     "_blank", 0, Args);
245cdf0e10cSrcweir         }
246cdf0e10cSrcweir         catch (com.sun.star.uno.Exception e)
247cdf0e10cSrcweir         {
248cdf0e10cSrcweir             throw new IllegalArgumentException("Document could not be opened");
249cdf0e10cSrcweir         }
250cdf0e10cSrcweir 
251cdf0e10cSrcweir         return oDoc;
252cdf0e10cSrcweir     } //finish openNewDoc
253cdf0e10cSrcweir 
254cdf0e10cSrcweir     /**
255cdf0e10cSrcweir      * loads a document of from a given url
256cdf0e10cSrcweir      * with arguments
257cdf0e10cSrcweir      * @return the XComponent Interface of the document
258cdf0e10cSrcweir      * @param url the URL of the document to load.
259cdf0e10cSrcweir      * @param Args arguments which passed to the document to load
260cdf0e10cSrcweir      * @param xMSF the MultiServiceFactory
261cdf0e10cSrcweir      */
loadDoc(XMultiServiceFactory xMSF, String url, PropertyValue[] Args)262cdf0e10cSrcweir     public static XComponent loadDoc(XMultiServiceFactory xMSF, String url,
263cdf0e10cSrcweir             PropertyValue[] Args)
264cdf0e10cSrcweir     {
265cdf0e10cSrcweir         XComponent oDoc = null;
266cdf0e10cSrcweir         if (Args == null)
267cdf0e10cSrcweir         {
268cdf0e10cSrcweir             Args = new PropertyValue[0];
269cdf0e10cSrcweir         }
270cdf0e10cSrcweir         try
271cdf0e10cSrcweir         {
272cdf0e10cSrcweir             oDoc = getCLoader(xMSF).loadComponentFromURL(url, "_blank", 0, Args);
273cdf0e10cSrcweir         }
274cdf0e10cSrcweir         catch (com.sun.star.uno.Exception e)
275cdf0e10cSrcweir         {
276cdf0e10cSrcweir             throw new IllegalArgumentException("Document could not be loaded");
277cdf0e10cSrcweir         }
278cdf0e10cSrcweir 
279cdf0e10cSrcweir         bringWindowToFront(oDoc);
280cdf0e10cSrcweir         return oDoc;
281cdf0e10cSrcweir     } //finish openNewDoc
282cdf0e10cSrcweir 
283cdf0e10cSrcweir     /**
284cdf0e10cSrcweir      * closes a given document
285cdf0e10cSrcweir      * @param DocumentToClose the document to close
286cdf0e10cSrcweir      */
closeDoc(XInterface DocumentToClose)287cdf0e10cSrcweir     public static void closeDoc(XInterface DocumentToClose)
288cdf0e10cSrcweir     {
289cdf0e10cSrcweir         if (DocumentToClose == null)
290cdf0e10cSrcweir         {
291cdf0e10cSrcweir             return;
292cdf0e10cSrcweir         }
293cdf0e10cSrcweir 
294cdf0e10cSrcweir         String kd = System.getProperty("KeepDocument");
295cdf0e10cSrcweir         if (kd != null)
296cdf0e10cSrcweir         {
297cdf0e10cSrcweir             System.out.println("The property 'KeepDocument' is set and so the document won't be disposed");
298cdf0e10cSrcweir             return;
299cdf0e10cSrcweir         }
300cdf0e10cSrcweir         XModifiable modified = (XModifiable) UnoRuntime.queryInterface(XModifiable.class, DocumentToClose);
301cdf0e10cSrcweir         XCloseable closer = (XCloseable) UnoRuntime.queryInterface(XCloseable.class, DocumentToClose);
302cdf0e10cSrcweir 
303cdf0e10cSrcweir         try
304cdf0e10cSrcweir         {
305cdf0e10cSrcweir             if (modified != null)
306cdf0e10cSrcweir             {
307cdf0e10cSrcweir                 modified.setModified(false);
308cdf0e10cSrcweir             }
309cdf0e10cSrcweir             closer.close(true);
310cdf0e10cSrcweir         }
311cdf0e10cSrcweir         catch (com.sun.star.util.CloseVetoException e)
312cdf0e10cSrcweir         {
313cdf0e10cSrcweir             // e.printStackTrace();
314cdf0e10cSrcweir             System.out.println("Couldn't close document");
315cdf0e10cSrcweir         }
316cdf0e10cSrcweir         catch (com.sun.star.lang.DisposedException e)
317cdf0e10cSrcweir         {
318cdf0e10cSrcweir             // e.printStackTrace();
319cdf0e10cSrcweir             System.out.println("Couldn't close document");
320cdf0e10cSrcweir         }
321cdf0e10cSrcweir         catch (java.lang.NullPointerException e)
322cdf0e10cSrcweir         {
323cdf0e10cSrcweir             // e.printStackTrace();
324cdf0e10cSrcweir             System.out.println("Couldn't close document");
325cdf0e10cSrcweir         }
326cdf0e10cSrcweir         catch (com.sun.star.beans.PropertyVetoException e)
327cdf0e10cSrcweir         {
328cdf0e10cSrcweir             // e.printStackTrace();
329cdf0e10cSrcweir             System.out.println("Couldn't close document");
330cdf0e10cSrcweir         }
331cdf0e10cSrcweir     }
332cdf0e10cSrcweir 
333cdf0e10cSrcweir     /**
334cdf0e10cSrcweir      * Creates a floating XWindow with the size of X=500 Y=100 width=400 height=600
335cdf0e10cSrcweir      * @param xMSF the MultiServiceFactory
336cdf0e10cSrcweir      * @throws lib.StatusException if it is not possible to create a floating window a lib.StatusException was thrown
337cdf0e10cSrcweir      * @return a floating XWindow
338cdf0e10cSrcweir      */
createFloatingWindow(XMultiServiceFactory xMSF)339cdf0e10cSrcweir     public static XWindowPeer createFloatingWindow(XMultiServiceFactory xMSF)
340cdf0e10cSrcweir             throws StatusException
341cdf0e10cSrcweir     {
342cdf0e10cSrcweir         return createFloatingWindow(xMSF, 500, 100, 400, 600);
343cdf0e10cSrcweir     }
344cdf0e10cSrcweir 
345cdf0e10cSrcweir     /**
346cdf0e10cSrcweir      * Creates a floating XWindow on the given position and size.
347cdf0e10cSrcweir      * @return a floating XWindow
348cdf0e10cSrcweir      * @param X the X-Postion of the floating XWindow
349cdf0e10cSrcweir      * @param Y the Y-Postion of the floating XWindow
350cdf0e10cSrcweir      * @param width the width of the floating XWindow
351cdf0e10cSrcweir      * @param height the height of the floating XWindow
352cdf0e10cSrcweir      * @param xMSF the MultiServiceFactory
353cdf0e10cSrcweir      * @throws lib.StatusException if it is not possible to create a floating window a lib.StatusException was thrown
354cdf0e10cSrcweir      */
createFloatingWindow(XMultiServiceFactory xMSF, int X, int Y, int width, int height)355cdf0e10cSrcweir     public static XWindowPeer createFloatingWindow(XMultiServiceFactory xMSF, int X, int Y, int width, int height)
356cdf0e10cSrcweir             throws StatusException
357cdf0e10cSrcweir     {
358cdf0e10cSrcweir 
359cdf0e10cSrcweir         XInterface oObj = null;
360cdf0e10cSrcweir 
361cdf0e10cSrcweir         try
362cdf0e10cSrcweir         {
363cdf0e10cSrcweir             oObj = (XInterface) xMSF.createInstance("com.sun.star.awt.Toolkit");
364cdf0e10cSrcweir         }
365cdf0e10cSrcweir         catch (com.sun.star.uno.Exception e)
366cdf0e10cSrcweir         {
367cdf0e10cSrcweir             throw new StatusException("Couldn't get toolkit", e);
368cdf0e10cSrcweir         }
369cdf0e10cSrcweir 
370cdf0e10cSrcweir         XToolkit tk = (XToolkit) UnoRuntime.queryInterface(
371cdf0e10cSrcweir                 XToolkit.class, oObj);
372cdf0e10cSrcweir 
373cdf0e10cSrcweir         WindowDescriptor descriptor = new com.sun.star.awt.WindowDescriptor();
374cdf0e10cSrcweir 
375cdf0e10cSrcweir         descriptor.Type = com.sun.star.awt.WindowClass.TOP;
376cdf0e10cSrcweir         descriptor.WindowServiceName = "modelessdialog";
377cdf0e10cSrcweir         descriptor.ParentIndex = -1;
378cdf0e10cSrcweir 
379cdf0e10cSrcweir         Rectangle bounds = new com.sun.star.awt.Rectangle();
380cdf0e10cSrcweir         bounds.X = X;
381cdf0e10cSrcweir         bounds.Y = Y;
382cdf0e10cSrcweir         bounds.Width = width;
383cdf0e10cSrcweir         bounds.Height = height;
384cdf0e10cSrcweir 
385cdf0e10cSrcweir         descriptor.Bounds = bounds;
386cdf0e10cSrcweir         descriptor.WindowAttributes = (com.sun.star.awt.WindowAttribute.BORDER +
387cdf0e10cSrcweir                 com.sun.star.awt.WindowAttribute.MOVEABLE +
388cdf0e10cSrcweir                 com.sun.star.awt.WindowAttribute.SIZEABLE +
389cdf0e10cSrcweir                 com.sun.star.awt.WindowAttribute.CLOSEABLE +
390cdf0e10cSrcweir                 com.sun.star.awt.VclWindowPeerAttribute.CLIPCHILDREN);
391cdf0e10cSrcweir 
392cdf0e10cSrcweir         XWindowPeer xWindow = null;
393cdf0e10cSrcweir 
394cdf0e10cSrcweir         try
395cdf0e10cSrcweir         {
396cdf0e10cSrcweir             xWindow = tk.createWindow(descriptor);
397cdf0e10cSrcweir         }
398cdf0e10cSrcweir         catch (com.sun.star.lang.IllegalArgumentException e)
399cdf0e10cSrcweir         {
400cdf0e10cSrcweir             throw new StatusException("Could not create window", e);
401cdf0e10cSrcweir         }
402cdf0e10cSrcweir 
403cdf0e10cSrcweir         return xWindow;
404cdf0e10cSrcweir 
405cdf0e10cSrcweir     }
406cdf0e10cSrcweir 
407cdf0e10cSrcweir     /**
408cdf0e10cSrcweir      * zoom to have a view over the hole page
409cdf0e10cSrcweir      * @param xDoc the document to zoom
410cdf0e10cSrcweir      */
zoomToEntirePage(XInterface xDoc)411cdf0e10cSrcweir     public static void zoomToEntirePage(XInterface xDoc)
412cdf0e10cSrcweir     {
413cdf0e10cSrcweir         try
414cdf0e10cSrcweir         {
415cdf0e10cSrcweir             XModel xMod = (XModel) UnoRuntime.queryInterface(XModel.class, xDoc);
416cdf0e10cSrcweir             XInterface oCont = xMod.getCurrentController();
417cdf0e10cSrcweir             XViewSettingsSupplier oVSSupp = (XViewSettingsSupplier) UnoRuntime.queryInterface(XViewSettingsSupplier.class, oCont);
418cdf0e10cSrcweir 
419cdf0e10cSrcweir             XInterface oViewSettings = oVSSupp.getViewSettings();
420cdf0e10cSrcweir             XPropertySet oViewProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oViewSettings);
421cdf0e10cSrcweir             oViewProp.setPropertyValue("ZoomType",
422cdf0e10cSrcweir                     new Short(com.sun.star.view.DocumentZoomType.ENTIRE_PAGE));
423cdf0e10cSrcweir 
424cdf0e10cSrcweir             utils.shortWait(5000);
425cdf0e10cSrcweir         }
426cdf0e10cSrcweir         catch (Exception e)
427cdf0e10cSrcweir         {
428cdf0e10cSrcweir             System.out.println("Could not zoom to entire page: " + e.toString());
429cdf0e10cSrcweir         }
430cdf0e10cSrcweir 
431cdf0e10cSrcweir     }
432cdf0e10cSrcweir 
433cdf0e10cSrcweir     /**
434cdf0e10cSrcweir      * This function docks the Stylist onto the right side of the window.</p>
435cdf0e10cSrcweir      * Note:<P>
436cdf0e10cSrcweir      * Since the svt.viewoptions cache the view configuration at start up
437cdf0e10cSrcweir      * the chage of the docking will be effective at a restart.
438cdf0e10cSrcweir      * @param xMSF the XMultiServiceFactory
439cdf0e10cSrcweir      */
dockStylist(XMultiServiceFactory xMSF)440cdf0e10cSrcweir     public static void dockStylist(XMultiServiceFactory xMSF)
441cdf0e10cSrcweir     {
442cdf0e10cSrcweir         // prepare Window-Settings
443cdf0e10cSrcweir         try
444cdf0e10cSrcweir         {
445cdf0e10cSrcweir             ConfigHelper aConfig = new ConfigHelper(xMSF,
446cdf0e10cSrcweir                     "org.openoffice.Office.Views", false);
447cdf0e10cSrcweir 
448cdf0e10cSrcweir             // Is node "5539" (slot-id for navigator) available? If not, insert it
449cdf0e10cSrcweir             XNameReplace x5539 = aConfig.getOrInsertGroup("Windows", "5539");
450cdf0e10cSrcweir 
451cdf0e10cSrcweir             aConfig.updateGroupProperty(
452cdf0e10cSrcweir                     "Windows", "5539", "WindowState", "952,180,244,349;1;0,0,0,0;");
453cdf0e10cSrcweir 
454cdf0e10cSrcweir             aConfig.insertOrUpdateExtensibleGroupProperty(
455cdf0e10cSrcweir                     "Windows", "5539", "UserData", "Data", "V2,V,0,AL:(5,16,0/0/244/349,244;610)");
456cdf0e10cSrcweir 
457cdf0e10cSrcweir             // Is node "SplitWindow2" available? If not, instert it.
458cdf0e10cSrcweir             aConfig.getOrInsertGroup("Windows", "SplitWindow2");
459cdf0e10cSrcweir 
460cdf0e10cSrcweir             aConfig.insertOrUpdateExtensibleGroupProperty(
461cdf0e10cSrcweir                     "Windows", "SplitWindow2", "UserData", "UserItem", "V1,2,1,0,5539");
462cdf0e10cSrcweir 
463cdf0e10cSrcweir             aConfig.flush();
464cdf0e10cSrcweir             aConfig = null;
465cdf0e10cSrcweir 
466cdf0e10cSrcweir         }
467cdf0e10cSrcweir         catch (com.sun.star.uno.Exception e)
468cdf0e10cSrcweir         {
469cdf0e10cSrcweir             e.printStackTrace();
470cdf0e10cSrcweir         }
471cdf0e10cSrcweir     }
472cdf0e10cSrcweir 
473cdf0e10cSrcweir     /**
474cdf0e10cSrcweir      * Due to typo deprecated
475cdf0e10cSrcweir      * @param xModel
476cdf0e10cSrcweir      * @deprecated
477cdf0e10cSrcweir      */
478cdf0e10cSrcweir     @Deprecated
bringWindowToFromt(XModel xModel)479cdf0e10cSrcweir     public static void bringWindowToFromt(XModel xModel)
480cdf0e10cSrcweir     {
481cdf0e10cSrcweir         bringWindowToFront(xModel);
482cdf0e10cSrcweir     }
483cdf0e10cSrcweir 
484cdf0e10cSrcweir     /**
485cdf0e10cSrcweir      * This function brings a document to the front.<P>
486cdf0e10cSrcweir      * NOTE: it is not possible to change the window order of your Window-Manager!!
487cdf0e10cSrcweir      * Only the order of Office documents are changeable.
488cdf0e10cSrcweir      * @param xModel the XModel of the document to bring to top
489cdf0e10cSrcweir      */
bringWindowToFront(XModel xModel)490cdf0e10cSrcweir     public static void bringWindowToFront(XModel xModel)
491cdf0e10cSrcweir     {
492cdf0e10cSrcweir         // System.out.println("DEBUG: bring to front xModel");
493cdf0e10cSrcweir 
494cdf0e10cSrcweir         XTopWindow xTopWindow =
495cdf0e10cSrcweir                 (XTopWindow) UnoRuntime.queryInterface(
496cdf0e10cSrcweir                 XTopWindow.class,
497cdf0e10cSrcweir                 xModel.getCurrentController().getFrame().getContainerWindow());
498cdf0e10cSrcweir 
499cdf0e10cSrcweir         xTopWindow.toFront();
500cdf0e10cSrcweir     }
501cdf0e10cSrcweir 
bringWindowToFront(XComponent xComponent)502cdf0e10cSrcweir     public static void bringWindowToFront(XComponent xComponent)
503cdf0e10cSrcweir     {
504cdf0e10cSrcweir         // System.out.println("DEBUG: bring to front xComponent");
505cdf0e10cSrcweir         XModel xModel = (XModel) UnoRuntime.queryInterface(XModel.class, xComponent);
506cdf0e10cSrcweir         if (xModel != null)
507cdf0e10cSrcweir         {
508cdf0e10cSrcweir             bringWindowToFront(xModel);
509cdf0e10cSrcweir         }
510cdf0e10cSrcweir     }
511cdf0e10cSrcweir }
512