1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 package embeddedobj.test; 23 24 import java.awt.*; 25 import java.applet.*; 26 import java.awt.event.*; 27 import java.net.*; 28 import java.io.*; 29 30 import com.sun.star.awt.XBitmap; 31 import com.sun.star.awt.XWindow; 32 import com.sun.star.awt.XWindowPeer; 33 import com.sun.star.awt.XToolkit; 34 import com.sun.star.awt.XSystemChildFactory; 35 import com.sun.star.awt.WindowDescriptor; 36 import com.sun.star.awt.WindowClass; 37 import com.sun.star.awt.WindowAttribute; 38 import com.sun.star.awt.VclWindowPeerAttribute; 39 40 import com.sun.star.uno.UnoRuntime; 41 import com.sun.star.uno.AnyConverter; 42 import com.sun.star.uno.Any; 43 44 import com.sun.star.lang.XMultiServiceFactory; 45 import com.sun.star.lang.XSingleServiceFactory; 46 47 class WindowHelper { 48 createWindow( XMultiServiceFactory xFactory, NativeView aParent, java.awt.Rectangle aBounds )49 public static XWindow createWindow( XMultiServiceFactory xFactory, NativeView aParent, java.awt.Rectangle aBounds ) 50 { 51 XWindow xWindow = null; 52 XToolkit xToolkit = null; 53 54 // get access to toolkit of remote office to create the container window of new target frame 55 try{ 56 xToolkit = (XToolkit)UnoRuntime.queryInterface( XToolkit.class, 57 xFactory.createInstance("com.sun.star.awt.Toolkit") ); 58 } 59 catch( Exception ex ) 60 { 61 return null; 62 } 63 64 XSystemChildFactory xChildFactory = (XSystemChildFactory)UnoRuntime.queryInterface( 65 XSystemChildFactory.class, 66 xToolkit); 67 68 try 69 { 70 XWindowPeer xPeer = null; 71 Integer nHandle = aParent.getHWND(); 72 short nSystem = (short)aParent.getNativeWindowSystemType(); 73 byte[] lProcID = new byte[0]; 74 /* 75 try { 76 xPeer = xChildFactory.createSystemChild((Object)nHandle, lProcID, nSystem); 77 } 78 catch( Exception e ) 79 {} 80 */ 81 if (xPeer==null) 82 { 83 JavaWindowPeerFake aWrapper = new JavaWindowPeerFake(aParent); 84 85 XWindowPeer xParentPeer = (XWindowPeer)UnoRuntime.queryInterface( 86 XWindowPeer.class, 87 aWrapper); 88 89 WindowDescriptor aDescriptor = new WindowDescriptor(); 90 aDescriptor.Type = WindowClass.TOP; 91 aDescriptor.WindowServiceName = "workwindow"; 92 aDescriptor.ParentIndex = 1; 93 aDescriptor.Parent = xParentPeer; 94 aDescriptor.Bounds = new com.sun.star.awt.Rectangle( (int)aBounds.getX(), 95 (int)aBounds.getY(), 96 (int)aBounds.getWidth(), 97 (int)aBounds.getHeight() ); 98 99 System.out.println( "The rectangle for vcl window is:\nx = " + (int)aBounds.getX() 100 + "; y = " + (int)aBounds.getY() 101 + "; width = " + (int)aBounds.getWidth() 102 + "; height = " + (int)aBounds.getHeight() ); 103 104 if (nSystem == com.sun.star.lang.SystemDependent.SYSTEM_WIN32) 105 aDescriptor.WindowAttributes = WindowAttribute.SHOW; 106 else 107 aDescriptor.WindowAttributes = WindowAttribute.SYSTEMDEPENDENT; 108 109 aDescriptor.WindowAttributes |= VclWindowPeerAttribute.CLIPCHILDREN; 110 111 xPeer = xToolkit.createWindow( aDescriptor ); 112 } 113 114 xWindow = (XWindow)UnoRuntime.queryInterface( XWindow.class, xPeer); 115 if ( xWindow != null ) 116 xWindow.setPosSize( (int)aBounds.getX(), 117 (int)aBounds.getY(), 118 (int)aBounds.getWidth(), 119 (int)aBounds.getHeight(), 120 com.sun.star.awt.PosSize.POSSIZE ); 121 } 122 catch( Exception ex1 ) 123 { 124 System.out.println( "Exception on VCL window creation: " + ex1 ); 125 xWindow = null; 126 } 127 128 return xWindow; 129 } 130 getVCLBitmapFromBytes( XMultiServiceFactory xFactory, Object aAny )131 public static XBitmap getVCLBitmapFromBytes( XMultiServiceFactory xFactory, Object aAny ) 132 { 133 if ( !AnyConverter.isArray( aAny ) ) 134 throw new com.sun.star.uno.RuntimeException(); 135 136 Object[] aArgs = new Object[1]; 137 aArgs[0] = aAny; 138 XBitmap xResult = null; 139 140 try { 141 XSingleServiceFactory xBitmapFactory = (XSingleServiceFactory)UnoRuntime.queryInterface( 142 XSingleServiceFactory.class, 143 xFactory.createInstance( "com.sun.star.embed.BitmapCreator" ) ); 144 145 xResult = (XBitmap)UnoRuntime.queryInterface( 146 XBitmap.class, 147 xBitmapFactory.createInstanceWithArguments( aArgs ) ); 148 } 149 catch( Exception e ) 150 { 151 System.out.println( "Could not create VCL bitmap based on sequence," ); 152 System.out.println( "exception: " + e ); 153 } 154 155 return xResult; 156 } 157 }; 158 159