merged tag ooo/OOO330_m14
[LibreOffice.git] / embeddedobj / test / Container1 / WindowHelper.java
blob289542b833ac1c49406f5f70b3e8f173f0cf469a
1 package embeddedobj.test;
3 import java.awt.*;
4 import java.applet.*;
5 import java.awt.event.*;
6 import java.net.*;
7 import java.io.*;
9 import com.sun.star.awt.XBitmap;
10 import com.sun.star.awt.XWindow;
11 import com.sun.star.awt.XWindowPeer;
12 import com.sun.star.awt.XToolkit;
13 import com.sun.star.awt.XSystemChildFactory;
14 import com.sun.star.awt.WindowDescriptor;
15 import com.sun.star.awt.WindowClass;
16 import com.sun.star.awt.WindowAttribute;
17 import com.sun.star.awt.VclWindowPeerAttribute;
19 import com.sun.star.uno.UnoRuntime;
20 import com.sun.star.uno.AnyConverter;
21 import com.sun.star.uno.Any;
23 import com.sun.star.lang.XMultiServiceFactory;
24 import com.sun.star.lang.XSingleServiceFactory;
26 class WindowHelper {
28 public static XWindow createWindow( XMultiServiceFactory xFactory, NativeView aParent, java.awt.Rectangle aBounds )
30 XWindow xWindow = null;
31 XToolkit xToolkit = null;
33 // get access to toolkit of remote office to create the container window of new target frame
34 try{
35 xToolkit = (XToolkit)UnoRuntime.queryInterface( XToolkit.class,
36 xFactory.createInstance("com.sun.star.awt.Toolkit") );
38 catch( Exception ex )
40 return null;
43 XSystemChildFactory xChildFactory = (XSystemChildFactory)UnoRuntime.queryInterface(
44 XSystemChildFactory.class,
45 xToolkit);
47 try
49 XWindowPeer xPeer = null;
50 Integer nHandle = aParent.getHWND();
51 short nSystem = (short)aParent.getNativeWindowSystemType();
52 byte[] lProcID = new byte[0];
54 try {
55 xPeer = xChildFactory.createSystemChild((Object)nHandle, lProcID, nSystem);
57 catch( Exception e )
60 if (xPeer==null)
62 JavaWindowPeerFake aWrapper = new JavaWindowPeerFake(aParent);
64 XWindowPeer xParentPeer = (XWindowPeer)UnoRuntime.queryInterface(
65 XWindowPeer.class,
66 aWrapper);
68 WindowDescriptor aDescriptor = new WindowDescriptor();
69 aDescriptor.Type = WindowClass.TOP;
70 aDescriptor.WindowServiceName = "workwindow";
71 aDescriptor.ParentIndex = 1;
72 aDescriptor.Parent = xParentPeer;
73 aDescriptor.Bounds = new com.sun.star.awt.Rectangle( (int)aBounds.getX(),
74 (int)aBounds.getY(),
75 (int)aBounds.getWidth(),
76 (int)aBounds.getHeight() );
78 System.out.println( "The rectangle for vcl window is:\nx = " + (int)aBounds.getX()
79 + "; y = " + (int)aBounds.getY()
80 + "; width = " + (int)aBounds.getWidth()
81 + "; height = " + (int)aBounds.getHeight() );
83 if (nSystem == com.sun.star.lang.SystemDependent.SYSTEM_WIN32)
84 aDescriptor.WindowAttributes = WindowAttribute.SHOW;
85 else
86 aDescriptor.WindowAttributes = WindowAttribute.SYSTEMDEPENDENT;
88 aDescriptor.WindowAttributes |= VclWindowPeerAttribute.CLIPCHILDREN;
90 xPeer = xToolkit.createWindow( aDescriptor );
93 xWindow = (XWindow)UnoRuntime.queryInterface( XWindow.class, xPeer);
94 if ( xWindow != null )
95 xWindow.setPosSize( (int)aBounds.getX(),
96 (int)aBounds.getY(),
97 (int)aBounds.getWidth(),
98 (int)aBounds.getHeight(),
99 com.sun.star.awt.PosSize.POSSIZE );
101 catch( Exception ex1 )
103 System.out.println( "Exception on VCL window creation: " + ex1 );
104 xWindow = null;
107 return xWindow;
110 public static XBitmap getVCLBitmapFromBytes( XMultiServiceFactory xFactory, Object aAny )
112 if ( !AnyConverter.isArray( aAny ) )
113 throw new com.sun.star.uno.RuntimeException();
115 Object[] aArgs = new Object[1];
116 aArgs[0] = aAny;
117 XBitmap xResult = null;
119 try {
120 XSingleServiceFactory xBitmapFactory = (XSingleServiceFactory)UnoRuntime.queryInterface(
121 XSingleServiceFactory.class,
122 xFactory.createInstance( "com.sun.star.embed.BitmapCreator" ) );
124 xResult = (XBitmap)UnoRuntime.queryInterface(
125 XBitmap.class,
126 xBitmapFactory.createInstanceWithArguments( aArgs ) );
128 catch( Exception e )
130 System.out.println( "Could not create VCL bitmap based on sequence," );
131 System.out.println( "exception: " + e );
134 return xResult;