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