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